diff --git a/BUILD.gn b/BUILD.gn index 161ea680d..75143f08b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1973,13 +1973,6 @@ if (is_mac) { ] } - bundle_data("cefclient_resources_bundle_data_extensions_set_page_color") { - sources = gypi_paths2.cefclient_sources_resources_extensions_set_page_color - outputs = [ - "{{bundle_resources_dir}}/extensions/set_page_color/{{source_file_part}}", - ] - } - bundle_data("cefclient_resources_bundle_data_english") { sources = [ "tests/cefclient/resources/mac/English.lproj/InfoPlist.strings", @@ -2029,7 +2022,6 @@ if (is_mac) { gypi_paths2.cefclient_sources_mac deps = [ ":cefclient_resources_bundle_data", - ":cefclient_resources_bundle_data_extensions_set_page_color", ":cefclient_resources_bundle_data_english", ":cefclient_xibs", ] @@ -2219,11 +2211,6 @@ if (is_mac) { gypi_paths2.cefclient_sources_resources outputs = [ "${root_out_dir}/cefclient_files/{{source_file_part}}" ] } - - copy("copy_cefclient_files_extensions_set_page_color") { - sources = gypi_paths2.cefclient_sources_resources_extensions_set_page_color - outputs = [ "${root_out_dir}/cefclient_files/extensions/set_page_color/{{source_file_part}}" ] - } } executable("cefclient") { @@ -2294,7 +2281,6 @@ if (is_mac) { deps += [ ":copy_cefclient_files", - ":copy_cefclient_files_extensions_set_page_color", ] libs = [ diff --git a/cef_paths2.gypi b/cef_paths2.gypi index cb8537452..8bb587b40 100644 --- a/cef_paths2.gypi +++ b/cef_paths2.gypi @@ -167,8 +167,6 @@ 'shared_sources_browser': [ 'tests/shared/browser/client_app_browser.cc', 'tests/shared/browser/client_app_browser.h', - 'tests/shared/browser/extension_util.cc', - 'tests/shared/browser/extension_util.h', 'tests/shared/browser/file_util.cc', 'tests/shared/browser/file_util.h', 'tests/shared/browser/geometry_util.cc', @@ -338,13 +336,6 @@ 'tests/cefclient/resources/window.html', 'tests/cefclient/resources/xmlhttprequest.html', ], - 'cefclient_sources_resources_extensions_set_page_color': [ - 'tests/cefclient/resources/extensions/set_page_color/icon.png', - 'tests/cefclient/resources/extensions/set_page_color/manifest.json', - 'tests/cefclient/resources/extensions/set_page_color/popup.html', - 'tests/cefclient/resources/extensions/set_page_color/popup.js', - 'tests/cefclient/resources/extensions/set_page_color/README.md', - ], 'cefclient_sources_win': [ 'tests/cefclient/browser/browser_window_osr_win.cc', 'tests/cefclient/browser/browser_window_osr_win.h', @@ -491,13 +482,6 @@ 'tests/ceftests/dom_unittest.cc', 'tests/ceftests/download_unittest.cc', 'tests/ceftests/draggable_regions_unittest.cc', - 'tests/ceftests/extensions/background_unittest.cc', - 'tests/ceftests/extensions/chrome_alarms_unittest.cc', - 'tests/ceftests/extensions/chrome_storage_unittest.cc', - 'tests/ceftests/extensions/chrome_tabs_unittest.cc', - 'tests/ceftests/extensions/extension_test_handler.cc', - 'tests/ceftests/extensions/extension_test_handler.h', - 'tests/ceftests/extensions/view_unittest.cc', 'tests/ceftests/file_util_unittest.cc', 'tests/ceftests/frame_handler_unittest.cc', 'tests/ceftests/frame_unittest.cc', diff --git a/tests/cefclient/CMakeLists.txt.in b/tests/cefclient/CMakeLists.txt.in index 84396999a..44ebe5201 100644 --- a/tests/cefclient/CMakeLists.txt.in +++ b/tests/cefclient/CMakeLists.txt.in @@ -83,7 +83,6 @@ 'shared_sources_resources', 'cefclient_bundle_resources_mac:MAC', 'cefclient_sources_resources', - 'cefclient_sources_resources_extensions_set_page_color', ], }} diff --git a/tests/cefclient/browser/client_handler.cc b/tests/cefclient/browser/client_handler.cc index ca1bdf78a..54be0a163 100644 --- a/tests/cefclient/browser/client_handler.cc +++ b/tests/cefclient/browser/client_handler.cc @@ -23,7 +23,6 @@ #include "tests/cefclient/browser/main_context.h" #include "tests/cefclient/browser/root_window_manager.h" #include "tests/cefclient/browser/test_runner.h" -#include "tests/shared/browser/extension_util.h" #include "tests/shared/browser/resource_util.h" #include "tests/shared/common/binary_value_utils.h" #include "tests/shared/common/client_switches.h" @@ -1015,21 +1014,6 @@ void ClientHandler::OnAfterCreated(CefRefPtr browser) { SetOfflineState(browser, true); } -#if !defined(DISABLE_ALLOY_BOOTSTRAP) - if (use_alloy_style_ && browser->GetHost()->GetExtension()) { - // Browsers hosting extension apps should auto-resize. - browser->GetHost()->SetAutoResizeEnabled(true, CefSize(20, 20), - CefSize(1000, 1000)); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - if (extension_util::IsInternalExtension(extension->GetPath())) { - // Register the internal handler for extension resources. - extension_util::AddInternalExtensionToResourceManager( - extension, GetResourceManager()); - } - } -#endif - NotifyBrowserCreated(browser); } diff --git a/tests/cefclient/browser/resource.h b/tests/cefclient/browser/resource.h index 63031cbce..5adbc8002 100644 --- a/tests/cefclient/browser/resource.h +++ b/tests/cefclient/browser/resource.h @@ -70,11 +70,6 @@ #define IDS_WINDOW_ICON_2X_PNG 1025 #define IDS_XMLHTTPREQUEST_HTML 1026 -#define IDS_EXTENSIONS_SET_PAGE_COLOR_ICON_PNG 1030 -#define IDS_EXTENSIONS_SET_PAGE_COLOR_MANIFEST_JSON 1031 -#define IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_HTML 1032 -#define IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_JS 1033 - // Next default values for new objects // #ifdef APSTUDIO_INVOKED diff --git a/tests/cefclient/browser/resource_util_win_idmap.cc b/tests/cefclient/browser/resource_util_win_idmap.cc index 09488edba..40e1bdfd1 100644 --- a/tests/cefclient/browser/resource_util_win_idmap.cc +++ b/tests/cefclient/browser/resource_util_win_idmap.cc @@ -17,14 +17,6 @@ int GetResourceId(const char* resource_name) { {"binding.html", IDS_BINDING_HTML}, {"dialogs.html", IDS_DIALOGS_HTML}, {"draggable.html", IDS_DRAGGABLE_HTML}, - {"extensions/set_page_color/icon.png", - IDS_EXTENSIONS_SET_PAGE_COLOR_ICON_PNG}, - {"extensions/set_page_color/manifest.json", - IDS_EXTENSIONS_SET_PAGE_COLOR_MANIFEST_JSON}, - {"extensions/set_page_color/popup.html", - IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_HTML}, - {"extensions/set_page_color/popup.js", - IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_JS}, {"hang.html", IDS_HANG_HTML}, {"ipc_performance.html", IDS_IPC_PERFORMANCE_HTML}, {"localstorage.html", IDS_LOCALSTORAGE_HTML}, diff --git a/tests/cefclient/browser/root_window.cc b/tests/cefclient/browser/root_window.cc index 6e637cf80..1daea5bb5 100644 --- a/tests/cefclient/browser/root_window.cc +++ b/tests/cefclient/browser/root_window.cc @@ -29,20 +29,4 @@ scoped_refptr RootWindow::GetForBrowser(int browser_id) { browser_id); } -void RootWindow::OnExtensionsChanged(const ExtensionSet& extensions) { - REQUIRE_MAIN_THREAD(); - DCHECK(delegate_); - DCHECK(!WithExtension()); - - if (extensions.empty()) { - return; - } - - ExtensionSet::const_iterator it = extensions.begin(); - for (; it != extensions.end(); ++it) { - delegate_->CreateExtensionWindow(*it, CefRect(), nullptr, base::DoNothing(), - WithWindowlessRendering()); - } -} - } // namespace client diff --git a/tests/cefclient/browser/root_window.h b/tests/cefclient/browser/root_window.h index cdb6c44c2..6e84e749d 100644 --- a/tests/cefclient/browser/root_window.h +++ b/tests/cefclient/browser/root_window.h @@ -24,9 +24,6 @@ namespace client { enum class WindowType { NORMAL, - // The window is hosting an extension app. - EXTENSION, - // The window is a modal dialog. DIALOG, @@ -92,8 +89,6 @@ struct RootWindowConfig { std::string url; }; -typedef std::set> ExtensionSet; - // Represents a top-level native window in the browser process. While references // to this object are thread-safe the methods must be called on the main thread // unless otherwise indicated. @@ -135,18 +130,6 @@ class RootWindow // Called when the RootWindow is activated (becomes the foreground window). virtual void OnRootWindowActivated(RootWindow* root_window) = 0; - // Called when the browser is created for the RootWindow. - virtual void OnBrowserCreated(RootWindow* root_window, - CefRefPtr browser) = 0; - - // Create a window for |extension|. |source_bounds| are the bounds of the - // UI element, like a button, that triggered the extension. - virtual void CreateExtensionWindow(CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback, - bool with_osr) = 0; - protected: virtual ~Delegate() = default; }; @@ -228,13 +211,6 @@ class RootWindow // Returns true if this window is using windowless rendering (osr). virtual bool WithWindowlessRendering() const = 0; - // Returns true if this window is hosting an extension app. - virtual bool WithExtension() const = 0; - - // Called when the set of loaded extensions changes. The default - // implementation will create a single window instance for each extension. - virtual void OnExtensionsChanged(const ExtensionSet& extensions); - protected: // Allow deletion via scoped_refptr only. friend struct DeleteOnMainThread; diff --git a/tests/cefclient/browser/root_window_gtk.cc b/tests/cefclient/browser/root_window_gtk.cc index 0a2fa3c89..7026cd225 100644 --- a/tests/cefclient/browser/root_window_gtk.cc +++ b/tests/cefclient/browser/root_window_gtk.cc @@ -85,7 +85,6 @@ RootWindowGtk::RootWindowGtk(bool use_alloy_style) with_controls_(false), always_on_top_(false), with_osr_(false), - with_extension_(false), is_popup_(false), initialized_(false), window_(nullptr), @@ -119,7 +118,6 @@ void RootWindowGtk::Init(RootWindow::Delegate* delegate, with_controls_ = config->with_controls; always_on_top_ = config->always_on_top; with_osr_ = config->with_osr; - with_extension_ = config->window_type == WindowType::EXTENSION; start_rect_ = config->bounds; CreateBrowserWindow(config->url); @@ -279,11 +277,6 @@ bool RootWindowGtk::WithWindowlessRendering() const { return with_osr_; } -bool RootWindowGtk::WithExtension() const { - REQUIRE_MAIN_THREAD(); - return with_extension_; -} - void RootWindowGtk::CreateBrowserWindow(const std::string& startup_url) { if (with_osr_) { OsrRendererSettings settings = {}; @@ -460,8 +453,6 @@ void RootWindowGtk::OnBrowserCreated(CefRefPtr browser) { if (is_popup_) { CreateRootWindow(CefBrowserSettings(), false); } - - delegate_->OnBrowserCreated(this, browser); } void RootWindowGtk::OnBrowserWindowClosing() { diff --git a/tests/cefclient/browser/root_window_gtk.h b/tests/cefclient/browser/root_window_gtk.h index 467972af7..36480cc77 100644 --- a/tests/cefclient/browser/root_window_gtk.h +++ b/tests/cefclient/browser/root_window_gtk.h @@ -45,7 +45,6 @@ class RootWindowGtk : public RootWindow, public BrowserWindow::Delegate { CefRefPtr GetBrowser() const override; ClientWindowHandle GetWindowHandle() const override; bool WithWindowlessRendering() const override; - bool WithExtension() const override; private: void CreateBrowserWindow(const std::string& startup_url); @@ -129,7 +128,6 @@ class RootWindowGtk : public RootWindow, public BrowserWindow::Delegate { bool with_controls_; bool always_on_top_; bool with_osr_; - bool with_extension_; bool is_popup_; CefRect start_rect_; std::unique_ptr browser_window_; diff --git a/tests/cefclient/browser/root_window_mac.h b/tests/cefclient/browser/root_window_mac.h index 38004f865..62d9a0fef 100644 --- a/tests/cefclient/browser/root_window_mac.h +++ b/tests/cefclient/browser/root_window_mac.h @@ -48,7 +48,6 @@ class RootWindowMac : public RootWindow, public BrowserWindow::Delegate { CefRefPtr GetBrowser() const override; ClientWindowHandle GetWindowHandle() const override; bool WithWindowlessRendering() const override; - bool WithExtension() const override; // BrowserWindow::Delegate methods. bool UseAlloyStyle() const override { return IsAlloyStyle(); } diff --git a/tests/cefclient/browser/root_window_mac.mm b/tests/cefclient/browser/root_window_mac.mm index 56fe16dbf..4628990e1 100644 --- a/tests/cefclient/browser/root_window_mac.mm +++ b/tests/cefclient/browser/root_window_mac.mm @@ -218,7 +218,6 @@ class RootWindowMacImpl CefRefPtr GetBrowser() const; ClientWindowHandle GetWindowHandle() const; bool WithWindowlessRendering() const; - bool WithExtension() const; // BrowserWindow::Delegate methods. void OnBrowserCreated(CefRefPtr browser); @@ -237,7 +236,6 @@ class RootWindowMacImpl RootWindowMac& root_window_; bool with_controls_ = false; bool with_osr_ = false; - bool with_extension_ = false; bool is_popup_ = false; CefRect initial_bounds_; cef_show_state_t initial_show_state_ = CEF_SHOW_STATE_NORMAL; @@ -279,7 +277,6 @@ void RootWindowMacImpl::Init(RootWindow::Delegate* delegate, with_controls_ = config->with_controls; with_osr_ = config->with_osr; - with_extension_ = config->window_type == WindowType::EXTENSION; if (!config->bounds.IsEmpty()) { // Initial state was specified via the config object. @@ -460,11 +457,6 @@ bool RootWindowMacImpl::WithWindowlessRendering() const { return with_osr_; } -bool RootWindowMacImpl::WithExtension() const { - REQUIRE_MAIN_THREAD(); - return with_extension_; -} - void RootWindowMacImpl::OnNativeWindowClosed() { window_ = nil; window_destroyed_ = true; @@ -650,8 +642,6 @@ void RootWindowMacImpl::OnBrowserCreated(CefRefPtr browser) { if (is_popup_) { CreateRootWindow(CefBrowserSettings(), false); } - - root_window_.delegate_->OnBrowserCreated(&root_window_, browser); } void RootWindowMacImpl::OnBrowserWindowDestroyed() { @@ -841,10 +831,6 @@ bool RootWindowMac::WithWindowlessRendering() const { return impl_->WithWindowlessRendering(); } -bool RootWindowMac::WithExtension() const { - return impl_->WithExtension(); -} - void RootWindowMac::OnBrowserCreated(CefRefPtr browser) { impl_->OnBrowserCreated(browser); } diff --git a/tests/cefclient/browser/root_window_manager.cc b/tests/cefclient/browser/root_window_manager.cc index 108b3616c..8771d9a77 100644 --- a/tests/cefclient/browser/root_window_manager.cc +++ b/tests/cefclient/browser/root_window_manager.cc @@ -13,7 +13,6 @@ #include "tests/cefclient/browser/default_client_handler.h" #include "tests/cefclient/browser/main_context.h" #include "tests/cefclient/browser/test_runner.h" -#include "tests/shared/browser/extension_util.h" #include "tests/shared/browser/file_util.h" #include "tests/shared/browser/resource_util.h" #include "tests/shared/common/client_switches.h" @@ -22,8 +21,7 @@ namespace client { namespace { -class ClientRequestContextHandler : public CefRequestContextHandler, - public CefExtensionHandler { +class ClientRequestContextHandler : public CefRequestContextHandler { public: using CreateCallback = RootWindow::Delegate::RequestContextCallback; @@ -35,38 +33,6 @@ class ClientRequestContextHandler : public CefRequestContextHandler, CefRefPtr request_context) override { CEF_REQUIRE_UI_THREAD(); -#if !defined(DISABLE_ALLOY_BOOTSTRAP) - const auto main_context = MainContext::Get(); - CefRefPtr command_line = - CefCommandLine::GetGlobalCommandLine(); - - if (!main_context->UseChromeBootstrap() && - command_line->HasSwitch(switches::kLoadExtension)) { - // Alloy implementation for loading extensions. Chrome runtime handles - // this internally. - if (main_context->GetRootWindowManager()->request_context_per_browser()) { - // The example extension loading implementation requires all browsers to - // share the same request context. - LOG(ERROR) - << "Cannot mix --load-extension and --request-context-per-browser"; - } else { - // Load one or more extension paths specified on the command-line and - // delimited with semicolon. - const std::string& extension_path = - command_line->GetSwitchValue(switches::kLoadExtension); - if (!extension_path.empty()) { - std::string part; - std::istringstream f(extension_path); - while (getline(f, part, ';')) { - if (!part.empty()) { - extension_util::LoadExtension(request_context, part, this); - } - } - } - } - } -#endif // !defined(DISABLE_ALLOY_BOOTSTRAP) - // Allow the startup URL to create popups that bypass the popup blocker. // For example, via Tests > New Popup from the top menu. This applies for // for the Chrome runtime only. @@ -83,31 +49,6 @@ class ClientRequestContextHandler : public CefRequestContextHandler, } } - // CefExtensionHandler methods: - void OnExtensionLoaded(CefRefPtr extension) override { - CEF_REQUIRE_UI_THREAD(); - MainContext::Get()->GetRootWindowManager()->AddExtension(extension); - } - - CefRefPtr GetActiveBrowser(CefRefPtr extension, - CefRefPtr browser, - bool include_incognito) override { - CEF_REQUIRE_UI_THREAD(); - - // Return the browser for the active/foreground window. - CefRefPtr active_browser = - MainContext::Get()->GetRootWindowManager()->GetActiveBrowser(); - if (!active_browser) { - LOG(WARNING) - << "No active browser available for extension " - << browser->GetHost()->GetExtension()->GetIdentifier().ToString(); - } else { - // The active browser should not be hosting an extension. - DCHECK(!active_browser->GetHost()->GetExtension()); - } - return active_browser; - } - private: CreateCallback create_callback_; @@ -227,59 +168,6 @@ scoped_refptr RootWindowManager::CreateRootWindowAsPopup( return root_window; } -scoped_refptr RootWindowManager::CreateRootWindowAsExtension( - CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback, - bool with_controls, - bool with_osr) { - const std::string& extension_url = extension_util::GetExtensionURL(extension); - if (extension_url.empty()) { - NOTREACHED() << "Extension cannot be loaded directly."; - return nullptr; - } - - // Create an initially hidden browser window that loads the extension URL. - // We'll show the window when the desired size becomes available via - // ClientHandler::OnAutoResize. - auto config = std::make_unique(); - config->window_type = WindowType::EXTENSION; - config->with_controls = with_controls; - config->with_osr = with_osr; - config->initially_hidden = true; - config->source_bounds = source_bounds; - config->parent_window = parent_window; - config->close_callback = std::move(close_callback); - config->url = extension_url; - return CreateRootWindow(std::move(config)); -} - -bool RootWindowManager::HasRootWindowAsExtension( - CefRefPtr extension) { - REQUIRE_MAIN_THREAD(); - - for (auto root_window : root_windows_) { - if (!root_window->WithExtension()) { - continue; - } - - CefRefPtr browser = root_window->GetBrowser(); - if (!browser) { - continue; - } - - CefRefPtr browser_extension = - browser->GetHost()->GetExtension(); - DCHECK(browser_extension); - if (browser_extension->GetIdentifier() == extension->GetIdentifier()) { - return true; - } - } - - return false; -} - scoped_refptr RootWindowManager::GetWindowForBrowser( int browser_id) const { REQUIRE_MAIN_THREAD(); @@ -298,11 +186,6 @@ scoped_refptr RootWindowManager::GetActiveRootWindow() const { return active_root_window_; } -CefRefPtr RootWindowManager::GetActiveBrowser() const { - base::AutoLock lock_scope(active_browser_lock_); - return active_browser_; -} - void RootWindowManager::CloseAllWindows(bool force) { if (!CURRENTLY_ON_MAIN_THREAD()) { // Execute this method on the main thread. @@ -324,31 +207,6 @@ void RootWindowManager::CloseAllWindows(bool force) { } } -void RootWindowManager::AddExtension(CefRefPtr extension) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE(base::BindOnce(&RootWindowManager::AddExtension, - base::Unretained(this), extension)); - return; - } - - // Don't track extensions that can't be loaded directly. - if (extension_util::GetExtensionURL(extension).empty()) { - return; - } - - // Don't add the same extension multiple times. - ExtensionSet::const_iterator it = extensions_.begin(); - for (; it != extensions_.end(); ++it) { - if ((*it)->GetIdentifier() == extension->GetIdentifier()) { - return; - } - } - - extensions_.insert(extension); - NotifyExtensionsChanged(); -} - void RootWindowManager::OnRootWindowCreated( scoped_refptr root_window) { if (!CURRENTLY_ON_MAIN_THREAD()) { @@ -359,24 +217,10 @@ void RootWindowManager::OnRootWindowCreated( } root_windows_.insert(root_window); - if (!root_window->WithExtension()) { - root_window->OnExtensionsChanged(extensions_); - if (root_windows_.size() == 1U) { - // The first non-extension root window should be considered the active - // window. - OnRootWindowActivated(root_window.get()); - } - } -} - -void RootWindowManager::NotifyExtensionsChanged() { - REQUIRE_MAIN_THREAD(); - - for (auto root_window : root_windows_) { - if (!root_window->WithExtension()) { - root_window->OnExtensionsChanged(extensions_); - } + if (root_windows_.size() == 1U) { + // The first root window should be considered the active window. + OnRootWindowActivated(root_window.get()); } } @@ -482,9 +326,6 @@ void RootWindowManager::OnRootWindowDestroyed(RootWindow* root_window) { if (root_window == active_root_window_) { active_root_window_ = nullptr; - - base::AutoLock lock_scope(active_browser_lock_); - active_browser_ = nullptr; } if (terminate_when_all_windows_closed_ && root_windows_.empty()) { @@ -497,47 +338,11 @@ void RootWindowManager::OnRootWindowDestroyed(RootWindow* root_window) { void RootWindowManager::OnRootWindowActivated(RootWindow* root_window) { REQUIRE_MAIN_THREAD(); - if (root_window->WithExtension()) { - // We don't want extension apps to become the active RootWindow. - return; - } - if (root_window == active_root_window_) { return; } active_root_window_ = root_window; - - { - base::AutoLock lock_scope(active_browser_lock_); - // May be nullptr at this point, in which case we'll make the association in - // OnBrowserCreated. - active_browser_ = active_root_window_->GetBrowser(); - } -} - -void RootWindowManager::OnBrowserCreated(RootWindow* root_window, - CefRefPtr browser) { - REQUIRE_MAIN_THREAD(); - - if (root_window == active_root_window_) { - base::AutoLock lock_scope(active_browser_lock_); - active_browser_ = browser; - } -} - -void RootWindowManager::CreateExtensionWindow( - CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback, - bool with_osr) { - REQUIRE_MAIN_THREAD(); - - if (!HasRootWindowAsExtension(extension)) { - CreateRootWindowAsExtension(extension, source_bounds, parent_window, - std::move(close_callback), false, with_osr); - } } void RootWindowManager::CleanupOnUIThread() { diff --git a/tests/cefclient/browser/root_window_manager.h b/tests/cefclient/browser/root_window_manager.h index c3ebdf529..1dcb94b30 100644 --- a/tests/cefclient/browser/root_window_manager.h +++ b/tests/cefclient/browser/root_window_manager.h @@ -46,22 +46,6 @@ class RootWindowManager : public RootWindow::Delegate { CefRefPtr& client, CefBrowserSettings& settings); - // Create a new top-level native window to host |extension|. - // If |with_controls| is true the window will show controls. - // If |with_osr| is true the window will use off-screen rendering. - // This method can be called from anywhere. - scoped_refptr CreateRootWindowAsExtension( - CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback, - bool with_controls, - bool with_osr); - - // Returns true if a window hosting |extension| currently exists. Must be - // called on the main thread. - bool HasRootWindowAsExtension(CefRefPtr extension); - // Returns the RootWindow associated with the specified browser ID. Must be // called on the main thread. scoped_refptr GetWindowForBrowser(int browser_id) const; @@ -70,18 +54,10 @@ class RootWindowManager : public RootWindow::Delegate { // Must be called on the main thread. scoped_refptr GetActiveRootWindow() const; - // Returns the currently active/foreground browser. May return nullptr. Safe - // to call from any thread. - CefRefPtr GetActiveBrowser() const; - // Close all existing windows. If |force| is true onunload handlers will not // be executed. void CloseAllWindows(bool force); - // Manage the set of loaded extensions. RootWindows will be notified via the - // OnExtensionsChanged method. - void AddExtension(CefRefPtr extension); - bool request_context_per_browser() const { return request_context_per_browser_; } @@ -93,7 +69,6 @@ class RootWindowManager : public RootWindow::Delegate { ~RootWindowManager() override; void OnRootWindowCreated(scoped_refptr root_window); - void NotifyExtensionsChanged(); // RootWindow::Delegate methods. CefRefPtr GetRequestContext() override; @@ -103,13 +78,6 @@ class RootWindowManager : public RootWindow::Delegate { void OnExit(RootWindow* root_window) override; void OnRootWindowDestroyed(RootWindow* root_window) override; void OnRootWindowActivated(RootWindow* root_window) override; - void OnBrowserCreated(RootWindow* root_window, - CefRefPtr browser) override; - void CreateExtensionWindow(CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback, - bool with_osr) override; // |callback| may be nullptr. Must be called on the main thread. CefRefPtr CreateRequestContext( @@ -129,19 +97,11 @@ class RootWindowManager : public RootWindow::Delegate { // thread. scoped_refptr active_root_window_; - // The currently active/foreground browser. Access is protected by - // |active_browser_lock_; - mutable base::Lock active_browser_lock_; - CefRefPtr active_browser_; - // Singleton window used as the temporary parent for popup browsers. std::unique_ptr temp_window_; CefRefPtr shared_request_context_; - // Loaded extensions. Only accessed on the main thread. - ExtensionSet extensions_; - scoped_refptr image_cache_; DISALLOW_COPY_AND_ASSIGN(RootWindowManager); diff --git a/tests/cefclient/browser/root_window_views.cc b/tests/cefclient/browser/root_window_views.cc index a38867e12..276a78fa0 100644 --- a/tests/cefclient/browser/root_window_views.cc +++ b/tests/cefclient/browser/root_window_views.cc @@ -194,32 +194,11 @@ ClientWindowHandle RootWindowViews::GetWindowHandle() const { #endif } -bool RootWindowViews::WithExtension() const { - DCHECK(initialized_); - return config_->window_type == WindowType::EXTENSION; -} - bool RootWindowViews::WithControls() { DCHECK(initialized_); return config_->with_controls; } -void RootWindowViews::OnExtensionsChanged(const ExtensionSet& extensions) { - if (!CefCurrentlyOn(TID_UI)) { - // Execute this method on the UI thread. - CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::OnExtensionsChanged, - this, extensions)); - return; - } - - if (window_) { - window_->OnExtensionsChanged(extensions); - } else { - // Window may not exist yet for popups. - pending_extensions_ = extensions; - } -} - bool RootWindowViews::InitiallyHidden() { CEF_REQUIRE_UI_THREAD(); #if defined(OS_MAC) @@ -256,11 +235,6 @@ void RootWindowViews::OnViewsWindowCreated(CefRefPtr window) { DCHECK(!window_); window_ = window; window_->SetAlwaysOnTop(config_->always_on_top); - - if (!pending_extensions_.empty()) { - window_->OnExtensionsChanged(pending_extensions_); - pending_extensions_.clear(); - } } void RootWindowViews::OnViewsWindowClosing(CefRefPtr window) { @@ -312,22 +286,6 @@ ViewsWindow::Delegate* RootWindowViews::GetDelegateForPopup( return root_window; } -void RootWindowViews::CreateExtensionWindow(CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE(base::BindOnce(&RootWindowViews::CreateExtensionWindow, - this, extension, source_bounds, - parent_window, std::move(close_callback))); - return; - } - - delegate_->CreateExtensionWindow(extension, source_bounds, parent_window, - std::move(close_callback), false); -} - void RootWindowViews::OnTest(int test_id) { if (!CURRENTLY_ON_MAIN_THREAD()) { // Execute this method on the main thread. @@ -352,7 +310,6 @@ void RootWindowViews::OnBrowserCreated(CefRefPtr browser) { REQUIRE_MAIN_THREAD(); DCHECK(!browser_); browser_ = browser; - delegate_->OnBrowserCreated(this, browser); } void RootWindowViews::OnBrowserClosing(CefRefPtr browser) { diff --git a/tests/cefclient/browser/root_window_views.h b/tests/cefclient/browser/root_window_views.h index d0faba592..787591475 100644 --- a/tests/cefclient/browser/root_window_views.h +++ b/tests/cefclient/browser/root_window_views.h @@ -51,8 +51,6 @@ class RootWindowViews : public RootWindow, CefRefPtr GetBrowser() const override; ClientWindowHandle GetWindowHandle() const override; bool WithWindowlessRendering() const override { return false; } - bool WithExtension() const override; - void OnExtensionsChanged(const ExtensionSet& extensions) override; // ViewsWindow::Delegate methods: bool WithControls() override; @@ -67,10 +65,6 @@ class RootWindowViews : public RootWindow, void OnViewsWindowActivated(CefRefPtr window) override; ViewsWindow::Delegate* GetDelegateForPopup( CefRefPtr client) override; - void CreateExtensionWindow(CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback) override; void OnTest(int test_id) override; void OnExit() override; @@ -122,7 +116,6 @@ class RootWindowViews : public RootWindow, cef_show_state_t initial_show_state_ = CEF_SHOW_STATE_NORMAL; bool position_on_resize_ = false; CefRefPtr window_; - ExtensionSet pending_extensions_; scoped_refptr image_cache_; DISALLOW_COPY_AND_ASSIGN(RootWindowViews); diff --git a/tests/cefclient/browser/root_window_win.cc b/tests/cefclient/browser/root_window_win.cc index 229b1d92a..957a19fa7 100644 --- a/tests/cefclient/browser/root_window_win.cc +++ b/tests/cefclient/browser/root_window_win.cc @@ -135,7 +135,6 @@ void RootWindowWin::Init(RootWindow::Delegate* delegate, with_controls_ = config->with_controls; always_on_top_ = config->always_on_top; with_osr_ = config->with_osr; - with_extension_ = config->window_type == WindowType::EXTENSION; CreateBrowserWindow(config->url); @@ -316,11 +315,6 @@ bool RootWindowWin::WithWindowlessRendering() const { return with_osr_; } -bool RootWindowWin::WithExtension() const { - REQUIRE_MAIN_THREAD(); - return with_extension_; -} - void RootWindowWin::CreateBrowserWindow(const std::string& startup_url) { if (with_osr_) { OsrRendererSettings settings = {}; @@ -1071,8 +1065,6 @@ void RootWindowWin::OnBrowserCreated(CefRefPtr browser) { // Make sure the browser is sized correctly. OnSize(false); } - - delegate_->OnBrowserCreated(this, browser); } void RootWindowWin::OnBrowserWindowDestroyed() { diff --git a/tests/cefclient/browser/root_window_win.h b/tests/cefclient/browser/root_window_win.h index bb27820a9..ec5d74ee0 100644 --- a/tests/cefclient/browser/root_window_win.h +++ b/tests/cefclient/browser/root_window_win.h @@ -47,7 +47,6 @@ class RootWindowWin : public RootWindow, public BrowserWindow::Delegate { CefRefPtr GetBrowser() const override; ClientWindowHandle GetWindowHandle() const override; bool WithWindowlessRendering() const override; - bool WithExtension() const override; private: void ContinueInitOnUIThread(std::unique_ptr config, @@ -122,7 +121,6 @@ class RootWindowWin : public RootWindow, public BrowserWindow::Delegate { bool with_controls_ = false; bool always_on_top_ = false; bool with_osr_ = false; - bool with_extension_ = false; bool is_popup_ = false; CefRect initial_bounds_; cef_show_state_t initial_show_state_ = CEF_SHOW_STATE_NORMAL; diff --git a/tests/cefclient/browser/test_runner.cc b/tests/cefclient/browser/test_runner.cc index f6fd77ce3..21a6b7ad9 100644 --- a/tests/cefclient/browser/test_runner.cc +++ b/tests/cefclient/browser/test_runner.cc @@ -823,15 +823,6 @@ void SetupResourceManager(CefRefPtr resource_manager, } void Alert(CefRefPtr browser, const std::string& message) { - if (browser->GetHost()->GetExtension()) { - // Alerts originating from extension hosts should instead be displayed in - // the active browser. - browser = MainContext::Get()->GetRootWindowManager()->GetActiveBrowser(); - if (!browser) { - return; - } - } - // Escape special characters in the message. std::string msg = AsciiStrReplace(message, "\\", "\\\\"); msg = AsciiStrReplace(msg, "'", "\\'"); diff --git a/tests/cefclient/browser/views_window.cc b/tests/cefclient/browser/views_window.cc index 0cbc13416..bdae04e44 100644 --- a/tests/cefclient/browser/views_window.cc +++ b/tests/cefclient/browser/views_window.cc @@ -15,7 +15,6 @@ #include "tests/cefclient/browser/main_context.h" #include "tests/cefclient/browser/resource.h" #include "tests/cefclient/browser/views_style.h" -#include "tests/shared/browser/extension_util.h" #include "tests/shared/common/client_switches.h" #if !defined(OS_WIN) @@ -28,8 +27,6 @@ namespace client { namespace { -const char kDefaultExtensionIcon[] = "window_icon"; - // Default window size. constexpr int kDefaultWidth = 800; constexpr int kDefaultHeight = 600; @@ -53,10 +50,6 @@ enum ControlIds { // Reserved range of top menu button IDs. ID_TOP_MENU_FIRST, ID_TOP_MENU_LAST = ID_TOP_MENU_FIRST + 10, - - // Reserved range of extension button IDs. - ID_EXTENSION_BUTTON_FIRST, - ID_EXTENSION_BUTTON_LAST = ID_EXTENSION_BUTTON_FIRST + 10, }; typedef std::vector> LabelButtons; @@ -389,40 +382,6 @@ void ViewsWindow::OnBeforeContextMenu(CefRefPtr model) { views_style::ApplyTo(model); } -void ViewsWindow::OnExtensionsChanged(const ExtensionSet& extensions) { - CEF_REQUIRE_UI_THREAD(); - - if (extensions.empty()) { - if (!extensions_.empty()) { - extensions_.clear(); - UpdateExtensionControls(); - } - return; - } - - ImageCache::ImageInfoSet image_set; - - ExtensionSet::const_iterator it = extensions.begin(); - for (; it != extensions.end(); ++it) { - CefRefPtr extension = *it; - bool internal = false; - const std::string& icon_path = - extension_util::GetExtensionIconPath(extension, &internal); - if (!icon_path.empty()) { - // Load the extension icon. - image_set.push_back( - ImageCache::ImageInfo::Create1x(icon_path, icon_path, internal)); - } else { - // Get a nullptr image and use the default icon. - image_set.push_back(ImageCache::ImageInfo::Empty()); - } - } - - delegate_->GetImageCache()->LoadImages( - image_set, - base::BindOnce(&ViewsWindow::OnExtensionIconsLoaded, this, extensions)); -} - // static bool ViewsWindow::SupportsWindowRestore(WindowType type) { // Only support window restore with normal windows. @@ -587,26 +546,8 @@ void ViewsWindow::OnMenuButtonPressed( CefRefPtr button_pressed_lock) { CEF_REQUIRE_UI_THREAD(); - const int id = menu_button->GetID(); - if (id >= ID_EXTENSION_BUTTON_FIRST && id <= ID_EXTENSION_BUTTON_LAST) { - const size_t extension_idx = id - ID_EXTENSION_BUTTON_FIRST; - if (extension_idx >= extensions_.size()) { - LOG(ERROR) << "Invalid extension index " << extension_idx; - return; - } - - // Keep the button pressed until the extension window is closed. - extension_button_pressed_lock_ = button_pressed_lock; - - // Create a window for the extension. - delegate_->CreateExtensionWindow( - extensions_[extension_idx].extension_, menu_button->GetBoundsInScreen(), - window_, base::BindOnce(&ViewsWindow::OnExtensionWindowClosed, this)); - return; - } - DCHECK(with_controls_ || with_overlay_controls_); - DCHECK_EQ(ID_MENU_BUTTON, id); + DCHECK_EQ(ID_MENU_BUTTON, menu_button->GetID()); const auto button_bounds = menu_button->GetBoundsInScreen(); @@ -780,10 +721,8 @@ void ViewsWindow::OnWindowCreated(CefRefPtr window) { // Add the BrowserView as the only child of the Window. window_->AddChildView(browser_view_); - if (type_ != WindowType::EXTENSION) { - // Choose a reasonable minimum window size. - minimum_window_size_ = CefSize(100, 100); - } + // Choose a reasonable minimum window size. + minimum_window_size_ = CefSize(100, 100); } if (!delegate_->InitiallyHidden()) { @@ -811,7 +750,6 @@ void ViewsWindow::OnWindowDestroyed(CefRefPtr window) { menu_bar_->Reset(); menu_bar_ = nullptr; } - extensions_panel_ = nullptr; menu_button_ = nullptr; window_ = nullptr; } @@ -872,15 +810,7 @@ CefRefPtr ViewsWindow::GetParentWindow(CefRefPtr window, bool* is_menu, bool* can_activate_menu) { CEF_REQUIRE_UI_THREAD(); - CefRefPtr parent_window = delegate_->GetParentWindow(); - if (parent_window) { - // Extension windows behave as a menu and allow activation. - if (type_ == WindowType::EXTENSION) { - *is_menu = true; - *can_activate_menu = true; - } - } - return parent_window; + return delegate_->GetParentWindow(); } bool ViewsWindow::IsWindowModalDialog(CefRefPtr window) { @@ -965,18 +895,7 @@ bool ViewsWindow::OnKeyEvent(CefRefPtr window, const CefKeyEvent& event) { CEF_REQUIRE_UI_THREAD(); - if (!window_) { - return false; - } - - if (type_ == WindowType::EXTENSION && event.type == KEYEVENT_RAWKEYDOWN && - event.windows_key_code == VK_ESCAPE) { - // Close the extension window on escape. - Close(false); - return true; - } - - if (!with_controls_) { + if (!window_ || !with_controls_) { return false; } @@ -1048,16 +967,6 @@ void ViewsWindow::OnFocus(CefRefPtr view) { } } -void ViewsWindow::OnBlur(CefRefPtr view) { - CEF_REQUIRE_UI_THREAD(); - - const int view_id = view->GetID(); - if (view_id == ID_BROWSER_VIEW && type_ == WindowType::EXTENSION) { - // Close windows hosting extensions when the browser loses focus. - Close(false); - } -} - void ViewsWindow::OnWindowChanged(CefRefPtr view, bool added) { const int view_id = view->GetID(); if (view_id != ID_BROWSER_VIEW) { @@ -1158,7 +1067,7 @@ ViewsWindow::ViewsWindow(WindowType type, accepts_first_mouse_ = command_line->HasSwitch(switches::kAcceptsFirstMouse); // Without a window frame. - frameless_ = hide_frame || type_ == WindowType::EXTENSION; + frameless_ = hide_frame; // With an overlay that mimics window controls. with_overlay_controls_ = hide_frame && !hide_overlays && !with_controls_; @@ -1322,11 +1231,6 @@ void ViewsWindow::AddControls() { panel->AddChildView(browse_button); } panel->AddChildView(location_bar_); - - UpdateExtensionControls(); - DCHECK(extensions_panel_); - panel->AddChildView(extensions_panel_); - panel->AddChildView(menu_button_); // Allow |location| to grow and fill any remaining space. @@ -1435,88 +1339,6 @@ void ViewsWindow::ShowTopControls(bool show) { } } -void ViewsWindow::UpdateExtensionControls() { - CEF_REQUIRE_UI_THREAD(); - - if (!window_ || !with_controls_) { - return; - } - - if (!extensions_panel_) { - extensions_panel_ = CefPanel::CreatePanel(this); - - // Use a horizontal box layout for |panel|. - CefBoxLayoutSettings panel_layout_settings; - panel_layout_settings.horizontal = true; - CefRefPtr panel_layout = - extensions_panel_->SetToBoxLayout(panel_layout_settings); - } else { - extensions_panel_->RemoveAllChildViews(); - } - - if (extensions_.size() > - ID_EXTENSION_BUTTON_LAST - ID_EXTENSION_BUTTON_FIRST) { - LOG(WARNING) << "Too many extensions loaded. Some will be ignored."; - } - - ExtensionInfoSet::const_iterator it = extensions_.begin(); - for (int id = ID_EXTENSION_BUTTON_FIRST; - it != extensions_.end() && id <= ID_EXTENSION_BUTTON_LAST; ++id, ++it) { - CefRefPtr button = - CefMenuButton::CreateMenuButton(this, CefString()); - button->SetID(id); - button->SetImage(CEF_BUTTON_STATE_NORMAL, (*it).image_); - button->SetInkDropEnabled(true); - // Override the default minimum size. - button->SetMinimumSize(CefSize(0, 0)); - - extensions_panel_->AddChildView(button); - } - - CefRefPtr parent_view = extensions_panel_->GetParentView(); - if (parent_view) { - parent_view->InvalidateLayout(); - } -} - -void ViewsWindow::OnExtensionIconsLoaded(const ExtensionSet& extensions, - const ImageCache::ImageSet& images) { - if (!CefCurrentlyOn(TID_UI)) { - // Execute this method on the UI thread. - CefPostTask(TID_UI, base::BindOnce(&ViewsWindow::OnExtensionIconsLoaded, - this, extensions, images)); - return; - } - - DCHECK_EQ(extensions.size(), images.size()); - - extensions_.clear(); - - ExtensionSet::const_iterator it1 = extensions.begin(); - ImageCache::ImageSet::const_iterator it2 = images.begin(); - for (; it1 != extensions.end() && it2 != images.end(); ++it1, ++it2) { - CefRefPtr icon = *it2; - if (!icon) { - icon = delegate_->GetImageCache()->GetCachedImage(kDefaultExtensionIcon); - } - extensions_.emplace_back(*it1, icon); - } - - UpdateExtensionControls(); -} - -void ViewsWindow::OnExtensionWindowClosed() { - if (!CefCurrentlyOn(TID_UI)) { - // Execute this method on the UI thread. - CefPostTask(TID_UI, - base::BindOnce(&ViewsWindow::OnExtensionWindowClosed, this)); - return; - } - - // Restore the button state. - extension_button_pressed_lock_ = nullptr; -} - #if !defined(OS_MAC) void ViewsWindow::NudgeWindow() { NOTIMPLEMENTED(); diff --git a/tests/cefclient/browser/views_window.h b/tests/cefclient/browser/views_window.h index 3a596c1e9..31f1ee313 100644 --- a/tests/cefclient/browser/views_window.h +++ b/tests/cefclient/browser/views_window.h @@ -31,8 +31,6 @@ namespace client { -typedef std::set> ExtensionSet; - // Implements a CefWindow that hosts a single CefBrowserView and optional // Views-hosted controls. All methods must be called on the browser process UI // thread. @@ -84,13 +82,6 @@ class ViewsWindow : public CefBrowserViewDelegate, // Return the Delegate for the popup window controlled by |client|. virtual Delegate* GetDelegateForPopup(CefRefPtr client) = 0; - // Create a window for |extension|. |source_bounds| are the bounds of the - // UI element, like a button, that triggered the extension. - virtual void CreateExtensionWindow(CefRefPtr extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - base::OnceClosure close_callback) = 0; - // Called to execute a test. See resource.h for |test_id| values. virtual void OnTest(int test_id) = 0; @@ -130,7 +121,6 @@ class ViewsWindow : public CefBrowserViewDelegate, void SetDraggableRegions(const std::vector& regions); void TakeFocus(bool next); void OnBeforeContextMenu(CefRefPtr model); - void OnExtensionsChanged(const ExtensionSet& extensions); static bool SupportsWindowRestore(WindowType type); bool SupportsWindowRestore() const; @@ -207,7 +197,6 @@ class ViewsWindow : public CefBrowserViewDelegate, CefSize GetPreferredSize(CefRefPtr view) override; CefSize GetMinimumSize(CefRefPtr view) override; void OnFocus(CefRefPtr view) override; - void OnBlur(CefRefPtr view) override; void OnWindowChanged(CefRefPtr view, bool added) override; void OnLayoutChanged(CefRefPtr view, const CefRect& new_bounds) override; @@ -254,13 +243,6 @@ class ViewsWindow : public CefBrowserViewDelegate, // Show/hide top controls on the Window. void ShowTopControls(bool show); - // Update extension controls on the Window. - void UpdateExtensionControls(); - - void OnExtensionIconsLoaded(const ExtensionSet& extensions, - const ImageCache::ImageSet& images); - void OnExtensionWindowClosed(); - void NudgeWindow(); const WindowType type_; @@ -306,20 +288,6 @@ class ViewsWindow : public CefBrowserViewDelegate, bool can_go_back_ = false; bool can_go_forward_ = false; - // Structure representing an extension. - struct ExtensionInfo { - ExtensionInfo(CefRefPtr extension, CefRefPtr image) - : extension_(extension), image_(image) {} - - CefRefPtr extension_; - CefRefPtr image_; - }; - typedef std::vector ExtensionInfoSet; - - ExtensionInfoSet extensions_; - CefRefPtr extensions_panel_; - CefRefPtr extension_button_pressed_lock_; - IMPLEMENT_REFCOUNTING(ViewsWindow); DISALLOW_COPY_AND_ASSIGN(ViewsWindow); }; diff --git a/tests/cefclient/resources/extensions/set_page_color/README.md b/tests/cefclient/resources/extensions/set_page_color/README.md deleted file mode 100644 index 550bac344..000000000 --- a/tests/cefclient/resources/extensions/set_page_color/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Color Extension - -Demonstrates basic extension app loading and integration by using a popup to change the page color. - -## Usage - -Run `cefclient --load-extension=set_page_color`. - -When using the Views framework (`--use-views`) an extension icon will be added to the control bar and clicking the icon will open the extension window. When not using the Views framework an extension window will be opened automatically on application start. - -## Implementation - -Based on the [set_page_color](https://developer.chrome.com/extensions/samples#search:browser%20action%20with%20a%20popup) example extension. - -Calls: - - * [tabs.executeScript](https://developer.chrome.com/extensions/tabs#method-executeScript) diff --git a/tests/cefclient/resources/extensions/set_page_color/icon.png b/tests/cefclient/resources/extensions/set_page_color/icon.png deleted file mode 100644 index 46819c738..000000000 Binary files a/tests/cefclient/resources/extensions/set_page_color/icon.png and /dev/null differ diff --git a/tests/cefclient/resources/extensions/set_page_color/manifest.json b/tests/cefclient/resources/extensions/set_page_color/manifest.json deleted file mode 100644 index 48f551d9b..000000000 --- a/tests/cefclient/resources/extensions/set_page_color/manifest.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "A browser action with a popup that changes the page color", - "description": "Change the current page color", - "version": "1.0", - "permissions": [ - "tabs", "http://*/*", "https://*/*" - ], - "browser_action": { - "default_title": "Set this page's color.", - "default_icon": "icon.png", - "default_popup": "popup.html" - }, - "manifest_version": 2 -} diff --git a/tests/cefclient/resources/extensions/set_page_color/popup.html b/tests/cefclient/resources/extensions/set_page_color/popup.html deleted file mode 100644 index bf1b42b3f..000000000 --- a/tests/cefclient/resources/extensions/set_page_color/popup.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - Set Page Color Popup - - - - -
red
-
blue
-
green
-
yellow
- - diff --git a/tests/cefclient/resources/extensions/set_page_color/popup.js b/tests/cefclient/resources/extensions/set_page_color/popup.js deleted file mode 100644 index 6f627087c..000000000 --- a/tests/cefclient/resources/extensions/set_page_color/popup.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - - -function click(e) { - chrome.tabs.executeScript(null, - {code:"document.body.style.backgroundColor='" + e.target.id + "'"}); -} - -document.addEventListener('DOMContentLoaded', function () { - var divs = document.querySelectorAll('div'); - for (var i = 0; i < divs.length; i++) { - divs[i].addEventListener('click', click); - } -}); diff --git a/tests/cefclient/resources/win/cefclient.rc b/tests/cefclient/resources/win/cefclient.rc index 20080d635..756dd4da3 100644 --- a/tests/cefclient/resources/win/cefclient.rc +++ b/tests/cefclient/resources/win/cefclient.rc @@ -57,11 +57,6 @@ IDS_WINDOW_ICON_1X_PNG BINARY "..\\..\\..\\shared\\resources\\window_icon.1x.png IDS_WINDOW_ICON_2X_PNG BINARY "..\\..\\..\\shared\\resources\\window_icon.2x.png" IDS_XMLHTTPREQUEST_HTML BINARY "..\\xmlhttprequest.html" -IDS_EXTENSIONS_SET_PAGE_COLOR_ICON_PNG BINARY "..\\extensions\\set_page_color\\icon.png" -IDS_EXTENSIONS_SET_PAGE_COLOR_MANIFEST_JSON BINARY "..\\extensions\\set_page_color\\manifest.json" -IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_HTML BINARY "..\\extensions\\set_page_color\\popup.html" -IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_JS BINARY "..\\extensions\\set_page_color\\popup.js" - ///////////////////////////////////////////////////////////////////////////// // // Icon diff --git a/tests/ceftests/extensions/background_unittest.cc b/tests/ceftests/extensions/background_unittest.cc deleted file mode 100644 index 2aa2b887d..000000000 --- a/tests/ceftests/extensions/background_unittest.cc +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include "tests/ceftests/extensions/extension_test_handler.h" -#include "tests/ceftests/test_util.h" -#include "tests/shared/browser/client_app_browser.h" -#include "tests/shared/browser/extension_util.h" - -using client::ClientAppBrowser; - -namespace { - -const char kExtensionPath[] = "background-extension"; -const char kBackgroundScript[] = "background.js"; -// HTML file created internally to load the background script. -const char kGeneratedBackgroundPage[] = "_generated_background_page.html"; - -// Test load/unload of an extension with a background script. -class BackgroundLoadUnloadTestHandler : public ExtensionTestHandler { - public: - explicit BackgroundLoadUnloadTestHandler( - RequestContextType request_context_type) - : ExtensionTestHandler(request_context_type) { - // Only creating the extension browser. - set_create_main_browser(false); - } - - // CefExtensionHandler methods: - void OnExtensionLoaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension->IsLoaded()); - EXPECT_TRUE(extension->GetLoaderContext()); - EXPECT_TRUE( - loader_request_context()->IsSame(extension->GetLoaderContext())); - VerifyExtension(extension); - - EXPECT_FALSE(got_loaded_); - got_loaded_.yes(); - - EXPECT_FALSE(extension_); - extension_ = extension; - - background_page_url_ = GetExtensionURL(extension, kGeneratedBackgroundPage); - - // Add extension resources. - script_url_ = GetExtensionURL(extension, kBackgroundScript); - AddResource(script_url_, GetMessageJS("extension_onload"), - "text/javascript"); - } - - void OnExtensionUnloaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension); - EXPECT_FALSE(extension->IsLoaded()); - EXPECT_FALSE(extension->GetLoaderContext()); - - EXPECT_FALSE(got_unloaded_); - got_unloaded_.yes(); - - EXPECT_TRUE(extension_); - EXPECT_TRUE(extension_->IsSame(extension)); - - // The extension should no longer be registered with the context. - if (loader_request_context()) { - VerifyExtensionInContext(extension, loader_request_context(), false, - true); - } - if (request_context() && !request_context_same_loader()) { - VerifyExtensionInContext(extension, request_context(), false, false); - } - - extension_ = nullptr; - - // Execute asynchronously so call stacks have a chance to unwind. - // Will close the browser windows. - CefPostTask( - TID_UI, - base::BindOnce(&BackgroundLoadUnloadTestHandler::DestroyTest, this)); - } - - bool OnBeforeBackgroundBrowser(CefRefPtr extension, - const CefString& url, - CefRefPtr& client, - CefBrowserSettings& settings) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension->IsLoaded()); - EXPECT_TRUE(extension->GetLoaderContext()); - EXPECT_TRUE( - loader_request_context()->IsSame(extension->GetLoaderContext())); - VerifyExtension(extension); - - const std::string& background_page_url = - GetExtensionURL(extension, kGeneratedBackgroundPage); - EXPECT_STREQ(background_page_url.c_str(), url.ToString().c_str()); - - EXPECT_FALSE(client); - client = this; - - // Allow the browser creation. - return false; - } - - // CefLoadHandler methods: - void OnLoadingStateChange(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) override { - EXPECT_TRUE(browser->GetHost()->IsBackgroundHost()); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - if (isLoading) { - EXPECT_FALSE(extension_browser_); - extension_browser_ = browser; - } else { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - const std::string& url = browser->GetMainFrame()->GetURL(); - EXPECT_STREQ(background_page_url_.c_str(), url.c_str()); - - EXPECT_FALSE(got_load_done_); - got_load_done_.yes(); - - TriggerDestroyTestIfDone(); - } - } - - // CefResourceRequestHandler methods: - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - EXPECT_TRUE(browser->GetHost()->IsBackgroundHost()); - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - const std::string& url = request->GetURL(); - if (url == background_page_url_) { - EXPECT_FALSE(got_background_page_url_request_); - got_background_page_url_request_.yes(); - } else if (url == script_url_) { - EXPECT_FALSE(got_script_url_request_); - got_script_url_request_.yes(); - } else { - EXPECT_TRUE(false); // Not reached. - } - - // Handle the resource request. - return RoutingTestHandler::GetResourceHandler(browser, frame, request); - } - - CefRefPtr extension() const { return extension_; } - - // Verify |extension| contents. - void VerifyExtension(CefRefPtr extension) const { - EXPECT_STREQ(("extensions/" + std::string(kExtensionPath)).c_str(), - client::extension_util::GetInternalExtensionResourcePath( - extension->GetPath()) - .c_str()); - - CefRefPtr expected_manifest = CreateManifest(); - TestDictionaryEqual(expected_manifest, extension->GetManifest()); - - VerifyExtensionInContext(extension, loader_request_context(), true, true); - if (!request_context_same_loader()) { - VerifyExtensionInContext(extension, request_context(), true, false); - } - } - - std::string GetExtensionURL(CefRefPtr extension, - const std::string& resource_path) const { - const std::string& identifier = extension->GetIdentifier(); - const std::string& origin = - client::extension_util::GetExtensionOrigin(identifier); - EXPECT_FALSE(origin.empty()); - return origin + resource_path; - } - - protected: - void OnLoadExtensions() override { - LoadExtension(kExtensionPath, CreateManifest()); - } - - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - EXPECT_STREQ("extension_onload", message.c_str()); - EXPECT_TRUE(browser->GetHost()->IsBackgroundHost()); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_TRUE(browser->GetHost()->IsBackgroundHost()); - - EXPECT_FALSE(got_body_onload_); - got_body_onload_.yes(); - - TriggerDestroyTestIfDone(); - return true; - } - - void OnDestroyTest() override { - extension_browser_ = nullptr; - - EXPECT_TRUE(got_loaded_); - EXPECT_TRUE(got_background_page_url_request_); - EXPECT_TRUE(got_script_url_request_); - EXPECT_TRUE(got_body_onload_); - EXPECT_TRUE(got_load_done_); - EXPECT_TRUE(got_unloaded_); - } - - // Create a manifest with background script. - CefRefPtr CreateManifest() const { - CefRefPtr manifest = - CreateDefaultManifest(ApiPermissionsList()); - - CefRefPtr background = CefDictionaryValue::Create(); - CefRefPtr scripts = CefListValue::Create(); - scripts->SetString(0, kBackgroundScript); - background->SetList("scripts", scripts); - manifest->SetDictionary("background", background); - - return manifest; - } - - void TriggerDestroyTestIfDone() { - if (got_body_onload_ && got_load_done_) { - TriggerDestroyTest(); - } - } - - virtual void TriggerDestroyTest() { - // Execute asynchronously so call stacks have a chance to unwind. - CefPostTask(TID_UI, base::BindOnce( - &BackgroundLoadUnloadTestHandler::UnloadExtension, - this, extension_)); - } - - CefRefPtr extension_; - std::string script_url_; - std::string background_page_url_; - CefRefPtr extension_browser_; - - TrackCallback got_loaded_; - TrackCallback got_background_page_url_request_; - TrackCallback got_script_url_request_; - TrackCallback got_body_onload_; - TrackCallback got_load_done_; - TrackCallback got_unloaded_; - - IMPLEMENT_REFCOUNTING(BackgroundLoadUnloadTestHandler); - DISALLOW_COPY_AND_ASSIGN(BackgroundLoadUnloadTestHandler); -}; - -} // namespace - -EXTENSION_TEST_GROUP_ALL(BackgroundLoadUnload, BackgroundLoadUnloadTestHandler) - -namespace { - -// Same as above but without the unload. Only do this with a custom context to -// avoid poluting the global context. -class BackgroundLoadNoUnloadTestHandler - : public BackgroundLoadUnloadTestHandler { - public: - explicit BackgroundLoadNoUnloadTestHandler( - RequestContextType request_context_type) - : BackgroundLoadUnloadTestHandler(request_context_type) {} - - protected: - void TriggerDestroyTest() override { - // Release everything that references the request context. This should - // trigger unload of the extension. - CloseBrowser(extension_browser_, false); - extension_browser_ = nullptr; - ReleaseRequestContexts(); - } -}; - -} // namespace - -EXTENSION_TEST_GROUP_MINIMAL_CUSTOM(BackgroundLoadNoUnload, - BackgroundLoadNoUnloadTestHandler) diff --git a/tests/ceftests/extensions/chrome_alarms_unittest.cc b/tests/ceftests/extensions/chrome_alarms_unittest.cc deleted file mode 100644 index 25809a411..000000000 --- a/tests/ceftests/extensions/chrome_alarms_unittest.cc +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include "tests/ceftests/extensions/extension_test_handler.h" -#include "tests/ceftests/test_util.h" -#include "tests/shared/browser/extension_util.h" - -#define ALARMS_TEST_GROUP_ALL(name, test_class) \ - EXTENSION_TEST_GROUP_ALL(ChromeAlarms##name, test_class) -#define ALARMS_TEST_GROUP_MINIMAL(name, test_class) \ - EXTENSION_TEST_GROUP_MINIMAL(ChromeAlarms##name, test_class) - -namespace { - -const char kExtensionPath[] = "alarms-extension"; -const char kSuccessMessage[] = "success"; - -// Base class for testing chrome.alarms methods. -// See https://developer.chrome.com/extensions/alarms -class AlarmsTestHandler : public ExtensionTestHandler { - public: - explicit AlarmsTestHandler(RequestContextType request_context_type) - : ExtensionTestHandler(request_context_type) { - // Only creating the extension browser. - set_create_main_browser(false); - } - - // CefExtensionHandler methods: - void OnExtensionLoaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_FALSE(got_loaded_); - got_loaded_.yes(); - - // Verify |extension| contents. - EXPECT_FALSE(extension->GetIdentifier().empty()); - EXPECT_STREQ(("extensions/" + std::string(kExtensionPath)).c_str(), - client::extension_util::GetInternalExtensionResourcePath( - extension->GetPath()) - .c_str()); - TestDictionaryEqual(CreateManifest(), extension->GetManifest()); - - EXPECT_FALSE(extension_); - extension_ = extension; - - CreateBrowserForExtension(); - } - - void OnExtensionUnloaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension_); - EXPECT_TRUE(extension_->IsSame(extension)); - EXPECT_FALSE(got_unloaded_); - got_unloaded_.yes(); - extension_ = nullptr; - - // Execute asynchronously so call stacks have a chance to unwind. - // Will close the browser windows. - CefPostTask(TID_UI, base::BindOnce(&AlarmsTestHandler::DestroyTest, this)); - } - - // CefLoadHandler methods: - void OnLoadingStateChange(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) override { - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - if (isLoading) { - EXPECT_FALSE(extension_browser_); - extension_browser_ = browser; - } else { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - const std::string& url = browser->GetMainFrame()->GetURL(); - EXPECT_STREQ(extension_url_.c_str(), url.c_str()); - } - } - - // CefResourceRequestHandler methods: - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - const std::string& url = request->GetURL(); - EXPECT_STREQ(extension_url_.c_str(), url.c_str()); - - EXPECT_FALSE(got_url_request_); - got_url_request_.yes(); - - // Handle the resource request. - return RoutingTestHandler::GetResourceHandler(browser, frame, request); - } - - protected: - void OnLoadExtensions() override { - LoadExtension(kExtensionPath, CreateManifest()); - } - - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - if (message == "extension_onload") { - // From body onLoad in the extension browser. - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_FALSE(got_body_onload_); - got_body_onload_.yes(); - TriggerAlarmsApiJSFunction(); - return true; - } - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_FALSE(got_success_message_); - got_success_message_.yes(); - EXPECT_STREQ(kSuccessMessage, message.c_str()); - TriggerDestroyTest(); - return true; - } - - void OnDestroyTest() override { - extension_browser_ = nullptr; - - EXPECT_TRUE(got_loaded_); - EXPECT_TRUE(got_url_request_); - EXPECT_TRUE(got_body_onload_); - EXPECT_TRUE(got_trigger_api_function_); - EXPECT_TRUE(got_success_message_); - EXPECT_TRUE(got_unloaded_); - } - - // Create a manifest that grants access to the alarms API. - virtual CefRefPtr CreateManifest() const { - ApiPermissionsList api_permissions; - api_permissions.push_back("alarms"); - return CreateDefaultManifest(api_permissions); - } - - // Add resources in the extension browser. - virtual void OnAddExtensionResources(const std::string& origin) { - extension_url_ = origin + "extension.html"; - AddResource(extension_url_, GetExtensionHTML(), "text/html"); - } - - // Returns the chrome.alarms.* JS that is executed in the extension browser - // when the triggerAlarmsApi() JS function is called. - virtual std::string GetAlarmsApiJS() const = 0; - - // Returns the JS that will be loaded in the extension browser. This - // implements the triggerAlarmsApi() JS function called from - // TriggerAlarmsApiJSFunction(). - virtual std::string GetExtensionJS() const { - return "function triggerAlarmsApi() {" + GetAlarmsApiJS() + "}"; - } - - // Returns the HTML that will be loaded in the extension browser. - virtual std::string GetExtensionHTML() const { - return "Extension"; - } - - virtual void TriggerDestroyTest() { - // Execute asynchronously so call stacks have a chance to unwind. - CefPostTask(TID_UI, base::BindOnce(&AlarmsTestHandler::UnloadExtension, - this, extension_)); - } - - CefRefPtr extension() const { return extension_; } - std::string extension_url() const { return extension_url_; } - CefRefPtr extension_browser() const { return extension_browser_; } - - bool got_success_message() const { return got_success_message_; } - - private: - void CreateBrowserForExtension() { - const std::string& identifier = extension_->GetIdentifier(); - EXPECT_FALSE(identifier.empty()); - const std::string& origin = - client::extension_util::GetExtensionOrigin(identifier); - EXPECT_FALSE(origin.empty()); - - // Add extension resources. - OnAddExtensionResources(origin); - - // Create a browser to host the extension. - CreateBrowser(extension_url_, request_context()); - } - - void TriggerAlarmsApiJSFunction() { - EXPECT_FALSE(got_trigger_api_function_); - got_trigger_api_function_.yes(); - - extension_browser_->GetMainFrame()->ExecuteJavaScript("triggerAlarmsApi();", - extension_url_, 0); - } - - CefRefPtr extension_; - std::string extension_url_; - CefRefPtr extension_browser_; - - TrackCallback got_loaded_; - TrackCallback got_url_request_; - TrackCallback got_body_onload_; - TrackCallback got_trigger_api_function_; - TrackCallback got_success_message_; - TrackCallback got_unloaded_; -}; -} // namespace - -namespace { - -// Test for chrome.alarms.create(string name, object alarmInfo) -// and chrome.alarms.onAlarm.addListener(function callback) -class CreateAlarmTestHandler : public AlarmsTestHandler { - public: - explicit CreateAlarmTestHandler(RequestContextType request_context_type) - : AlarmsTestHandler(request_context_type) {} - - protected: - std::string GetAlarmsApiJS() const override { - return "chrome.alarms.onAlarm.addListener(function (alarm) {" + - GetMessageJS(kSuccessMessage) + - "});" - "chrome.alarms.create(\"test\", {delayInMinutes:0.01})"; - } - - private: - IMPLEMENT_REFCOUNTING(CreateAlarmTestHandler); - DISALLOW_COPY_AND_ASSIGN(CreateAlarmTestHandler); -}; -} // namespace - -ALARMS_TEST_GROUP_ALL(CreateAlarm, CreateAlarmTestHandler) - -namespace { - -// Test for chrome.alarms.get(string name, function callback) -class GetAlarmTestHandler : public AlarmsTestHandler { - public: - explicit GetAlarmTestHandler(RequestContextType request_context_type) - : AlarmsTestHandler(request_context_type) {} - - protected: - std::string GetAlarmsApiJS() const override { - return "chrome.alarms.create(\"test\", {delayInMinutes:1});" - "setTimeout(function() {" - "chrome.alarms.get(\"test\", function (alarm) {" + - GetMessageJS(kSuccessMessage) + "})}, 100)"; - } - - private: - IMPLEMENT_REFCOUNTING(GetAlarmTestHandler); - DISALLOW_COPY_AND_ASSIGN(GetAlarmTestHandler); -}; -} // namespace - -ALARMS_TEST_GROUP_MINIMAL(GetAlarm, GetAlarmTestHandler) - -namespace { - -// Test for chrome.alarms.getAll(function callback) -class GetAllAlarmsTestHandler : public AlarmsTestHandler { - public: - explicit GetAllAlarmsTestHandler(RequestContextType request_context_type) - : AlarmsTestHandler(request_context_type) {} - - protected: - std::string GetAlarmsApiJS() const override { - return "chrome.alarms.create(\"alarm1\", {delayInMinutes:1});" - "chrome.alarms.create(\"alarm2\", {delayInMinutes:1});" - "setTimeout(function() {" - "chrome.alarms.getAll(function (alarms) {" - "if (alarms.length == 2) {" + - GetMessageJS(kSuccessMessage) + "}})}, 100)"; - } - - private: - IMPLEMENT_REFCOUNTING(GetAllAlarmsTestHandler); - DISALLOW_COPY_AND_ASSIGN(GetAllAlarmsTestHandler); -}; -} // namespace - -ALARMS_TEST_GROUP_MINIMAL(GetAllAlarms, GetAllAlarmsTestHandler) - -namespace { - -// Test for chrome.alarms.clear(string name, function callback) -class ClearAlarmTestHandler : public AlarmsTestHandler { - public: - explicit ClearAlarmTestHandler(RequestContextType request_context_type) - : AlarmsTestHandler(request_context_type) {} - - protected: - std::string GetAlarmsApiJS() const override { - return "chrome.alarms.create(\"test\", {delayInMinutes:1});" - "setTimeout(function() {" - "chrome.alarms.clear(\"test\", function (wasCleared) {" - "if (wasCleared) {" + - GetMessageJS(kSuccessMessage) + "}})}, 100)"; - } - - private: - IMPLEMENT_REFCOUNTING(ClearAlarmTestHandler); - DISALLOW_COPY_AND_ASSIGN(ClearAlarmTestHandler); -}; -} // namespace - -ALARMS_TEST_GROUP_MINIMAL(ClearAlarm, ClearAlarmTestHandler) - -namespace { - -// Test for chrome.alarms.clearAll(function callback) -class ClearAllAlarmsTestHandler : public AlarmsTestHandler { - public: - explicit ClearAllAlarmsTestHandler(RequestContextType request_context_type) - : AlarmsTestHandler(request_context_type) {} - - protected: - std::string GetAlarmsApiJS() const override { - return "chrome.alarms.create(\"alarm1\", {delayInMinutes:1});" - "chrome.alarms.create(\"alarm2\", {delayInMinutes:1});" - "setTimeout(function() {" - "chrome.alarms.clearAll(function (wasCleared) {" - "if (wasCleared) {" + - GetMessageJS(kSuccessMessage) + "}})}, 100)"; - } - - private: - IMPLEMENT_REFCOUNTING(ClearAllAlarmsTestHandler); - DISALLOW_COPY_AND_ASSIGN(ClearAllAlarmsTestHandler); -}; -} // namespace - -ALARMS_TEST_GROUP_MINIMAL(ClearAllAlarms, ClearAllAlarmsTestHandler) diff --git a/tests/ceftests/extensions/chrome_storage_unittest.cc b/tests/ceftests/extensions/chrome_storage_unittest.cc deleted file mode 100644 index 28fe1c35c..000000000 --- a/tests/ceftests/extensions/chrome_storage_unittest.cc +++ /dev/null @@ -1,480 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include "tests/ceftests/extensions/extension_test_handler.h" -#include "tests/ceftests/test_util.h" -#include "tests/shared/browser/extension_util.h" - -#define STORAGE_TEST_GROUP_ALL(name, test_class) \ - EXTENSION_TEST_GROUP_ALL(ChromeStorage##name, test_class) -#define STORAGE_TEST_GROUP_MINIMAL(name, test_class) \ - EXTENSION_TEST_GROUP_MINIMAL(ChromeStorage##name, test_class) - -namespace { - -const char kExtensionPath[] = "storage-extension"; -const char kSuccessMessage[] = "success"; - -// Base class for testing chrome.storage methods. -// See https://developer.chrome.com/extensions/storage -class StorageTestHandler : public ExtensionTestHandler { - public: - explicit StorageTestHandler(RequestContextType request_context_type) - : ExtensionTestHandler(request_context_type) { - // Only creating the extension browser. - set_create_main_browser(false); - } - - // CefExtensionHandler methods: - void OnExtensionLoaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_FALSE(got_loaded_); - got_loaded_.yes(); - - // Verify |extension| contents. - EXPECT_FALSE(extension->GetIdentifier().empty()); - EXPECT_STREQ(("extensions/" + std::string(kExtensionPath)).c_str(), - client::extension_util::GetInternalExtensionResourcePath( - extension->GetPath()) - .c_str()); - TestDictionaryEqual(CreateManifest(), extension->GetManifest()); - - EXPECT_FALSE(extension_); - extension_ = extension; - - CreateBrowserForExtension(); - } - - void OnExtensionUnloaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension_); - EXPECT_TRUE(extension_->IsSame(extension)); - EXPECT_FALSE(got_unloaded_); - got_unloaded_.yes(); - extension_ = nullptr; - - // Execute asynchronously so call stacks have a chance to unwind. - // Will close the browser windows. - CefPostTask(TID_UI, base::BindOnce(&StorageTestHandler::DestroyTest, this)); - } - - // CefLoadHandler methods: - void OnLoadingStateChange(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) override { - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - if (isLoading) { - EXPECT_FALSE(extension_browser_); - extension_browser_ = browser; - } else { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - const std::string& url = browser->GetMainFrame()->GetURL(); - EXPECT_STREQ(extension_url_.c_str(), url.c_str()); - } - } - - // CefResourceRequestHandler methods: - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - const std::string& url = request->GetURL(); - EXPECT_STREQ(extension_url_.c_str(), url.c_str()); - - EXPECT_FALSE(got_url_request_); - got_url_request_.yes(); - - // Handle the resource request. - return RoutingTestHandler::GetResourceHandler(browser, frame, request); - } - - protected: - void OnLoadExtensions() override { - LoadExtension(kExtensionPath, CreateManifest()); - } - - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - if (message == "extension_onload") { - // From body onLoad in the extension browser. - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_FALSE(got_body_onload_); - got_body_onload_.yes(); - TriggerStorageApiJSFunction(); - return true; - } - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_FALSE(got_success_message_); - got_success_message_.yes(); - EXPECT_STREQ(kSuccessMessage, message.c_str()); - TriggerDestroyTest(); - return true; - } - - void OnDestroyTest() override { - extension_browser_ = nullptr; - - EXPECT_TRUE(got_loaded_); - EXPECT_TRUE(got_url_request_); - EXPECT_TRUE(got_body_onload_); - EXPECT_TRUE(got_trigger_api_function_); - EXPECT_TRUE(got_success_message_); - EXPECT_TRUE(got_unloaded_); - } - - // Create a manifest that grants access to the storage API. - virtual CefRefPtr CreateManifest() const { - ApiPermissionsList api_permissions; - api_permissions.push_back("storage"); - return CreateDefaultManifest(api_permissions); - } - - // Add resources in the extension browser. - virtual void OnAddExtensionResources(const std::string& origin) { - extension_url_ = origin + "extension.html"; - AddResource(extension_url_, GetExtensionHTML(), "text/html"); - } - - // Returns the chrome.storage.* JS that is executed in the extension browser - // when the triggerStorageApi() JS function is called. - virtual std::string GetStorageApiJS() const = 0; - - // Returns the JS that will be loaded in the extension browser. This - // implements the triggerStorageApi() JS function called from - // TriggerStorageApiJSFunction(). - virtual std::string GetExtensionJS() const { - return "function triggerStorageApi() {" + GetStorageApiJS() + "}"; - } - - // Returns the HTML that will be loaded in the extension browser. - virtual std::string GetExtensionHTML() const { - return "Extension"; - } - - virtual void TriggerDestroyTest() { - // Execute asynchronously so call stacks have a chance to unwind. - CefPostTask(TID_UI, base::BindOnce(&StorageTestHandler::UnloadExtension, - this, extension_)); - } - - CefRefPtr extension() const { return extension_; } - std::string extension_url() const { return extension_url_; } - CefRefPtr extension_browser() const { return extension_browser_; } - - bool got_success_message() const { return got_success_message_; } - - private: - void CreateBrowserForExtension() { - const std::string& identifier = extension_->GetIdentifier(); - EXPECT_FALSE(identifier.empty()); - const std::string& origin = - client::extension_util::GetExtensionOrigin(identifier); - EXPECT_FALSE(origin.empty()); - - // Add extension resources. - OnAddExtensionResources(origin); - - // Create a browser to host the extension. - CreateBrowser(extension_url_, request_context()); - } - - void TriggerStorageApiJSFunction() { - EXPECT_FALSE(got_trigger_api_function_); - got_trigger_api_function_.yes(); - - extension_browser_->GetMainFrame()->ExecuteJavaScript( - "triggerStorageApi();", extension_url_, 0); - } - - CefRefPtr extension_; - std::string extension_url_; - CefRefPtr extension_browser_; - - TrackCallback got_loaded_; - TrackCallback got_url_request_; - TrackCallback got_body_onload_; - TrackCallback got_trigger_api_function_; - TrackCallback got_success_message_; - TrackCallback got_unloaded_; -}; -} // namespace - -namespace { - -// Test for chrome.storage.local.set(object items, function callback) -// and for chrome.storage.local.get(string or array of string or object keys, -// function callback) -class LocalStorageTestHandler : public StorageTestHandler { - public: - explicit LocalStorageTestHandler(RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "chrome.storage.local.set({\"local_key_1\": \"local_value_1\"}, " - "function() {" - "chrome.storage.local.get(\"local_key_1\", function (items) {" - "if(items[\"local_key_1\"] == \"local_value_1\") {" + - GetMessageJS(kSuccessMessage) + - "}});" - "});"; - } - - private: - IMPLEMENT_REFCOUNTING(LocalStorageTestHandler); - DISALLOW_COPY_AND_ASSIGN(LocalStorageTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_ALL(LocalStorage, LocalStorageTestHandler) - -namespace { - -// Test for chrome.storage.local.getBytesInUse(string or array of string keys, -// function callback) -class LocalStorageGetBytesInUseTestHandler : public StorageTestHandler { - public: - explicit LocalStorageGetBytesInUseTestHandler( - RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "chrome.storage.local.set({\"local_key_2\": \"local_value_2\"}, " - "function() {" - "chrome.storage.local.getBytesInUse(\"local_key_2\", function " - "(bytesInUse) {" - "if (bytesInUse == 26) {" + - GetMessageJS(kSuccessMessage) + - "}});" - "});"; - } - - private: - IMPLEMENT_REFCOUNTING(LocalStorageGetBytesInUseTestHandler); - DISALLOW_COPY_AND_ASSIGN(LocalStorageGetBytesInUseTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_MINIMAL(LocalStorageGetBytesInUse, - LocalStorageGetBytesInUseTestHandler) - -namespace { - -// Test for chrome.storage.local.remove(string or array of string keys, function -// callback) -class LocalStorageRemoveTestHandler : public StorageTestHandler { - public: - explicit LocalStorageRemoveTestHandler( - RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "chrome.storage.local.set({\"local_key_3\": \"local_value_3\"}, " - "function() {" - "chrome.storage.local.remove(\"local_key_3\", function () {" - "chrome.storage.local.get(\"local_key_3\", function(items) {" - "if (items[\"local_key_3\"] == undefined) {" + - GetMessageJS(kSuccessMessage) + - "}})})" - "});"; - } - - private: - IMPLEMENT_REFCOUNTING(LocalStorageRemoveTestHandler); - DISALLOW_COPY_AND_ASSIGN(LocalStorageRemoveTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_MINIMAL(LocalStorageRemove, LocalStorageRemoveTestHandler) - -namespace { - -// Test for chrome.storage.local.clear(function callback) -class LocalStorageClearTestHandler : public StorageTestHandler { - public: - explicit LocalStorageClearTestHandler(RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "var value1Cleared = false;" - "var value2Cleared = false;" - "function checkCleared() {" - "if (value1Cleared && value2Cleared) {" + - GetMessageJS(kSuccessMessage) + - "}}" - "chrome.storage.local.set({\"local_key_4\": \"local_value_4\"," - "\"local_key_5\": \"local_value_5\"}, function() {" - "chrome.storage.local.clear(function () {" - - "chrome.storage.local.get(\"local_key_4\", function(items) {" - "if (items[\"local_key_4\"] == undefined) {" - "value1Cleared = true;" - "checkCleared();" - "}});" - - "chrome.storage.local.get(\"local_key_5\", function(items) {" - "if (items[\"local_key_5\"] == undefined) {" - "value2Cleared = true;" - "checkCleared();" - "}});" - "})});"; - } - - private: - IMPLEMENT_REFCOUNTING(LocalStorageClearTestHandler); - DISALLOW_COPY_AND_ASSIGN(LocalStorageClearTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_MINIMAL(LocalStorageClear, LocalStorageClearTestHandler) - -namespace { - -// Test for chrome.storage.sync.set(object items, function callback) -// and for chrome.storage.sync.get(string or array of string or object keys, -// function callback) -class SyncStorageTestHandler : public StorageTestHandler { - public: - explicit SyncStorageTestHandler(RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "chrome.storage.sync.set({\"sync_key_1\": \"sync_value_1\"}, " - "function() {" - "chrome.storage.sync.get(\"sync_key_1\", function (items) {" - "if (items[\"sync_key_1\"] == \"sync_value_1\") {" + - GetMessageJS(kSuccessMessage) + - "}});" - "});"; - } - - private: - IMPLEMENT_REFCOUNTING(SyncStorageTestHandler); - DISALLOW_COPY_AND_ASSIGN(SyncStorageTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_ALL(SyncStorage, SyncStorageTestHandler) - -namespace { - -// Test for chrome.storage.sync.getBytesInUse(string or array of string keys, -// function callback) -class SyncStorageGetBytesInUseTestHandler : public StorageTestHandler { - public: - explicit SyncStorageGetBytesInUseTestHandler( - RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "chrome.storage.sync.set({\"sync_key_2\": \"sync_value_2\"}, " - "function() {" - "chrome.storage.sync.getBytesInUse(\"sync_key_2\", function " - "(bytesInUse) {" - "if (bytesInUse == 24) {" + - GetMessageJS(kSuccessMessage) + - "}});" - "});"; - } - - private: - IMPLEMENT_REFCOUNTING(SyncStorageGetBytesInUseTestHandler); - DISALLOW_COPY_AND_ASSIGN(SyncStorageGetBytesInUseTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_MINIMAL(SyncStorageGetBytesInUse, - SyncStorageGetBytesInUseTestHandler) - -namespace { - -// Test for chrome.storage.sync.remove(string or array of string keys, function -// callback) -class SyncStorageRemoveTestHandler : public StorageTestHandler { - public: - explicit SyncStorageRemoveTestHandler(RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "chrome.storage.sync.set({\"sync_key_3\": \"sync_value_3\"}, " - "function() {" - "chrome.storage.sync.remove(\"sync_key_3\", function () {" - "chrome.storage.sync.get(\"sync_key_3\", function(items) {" - "if (items[\"sync_key_3\"] == undefined) {" + - GetMessageJS(kSuccessMessage) + - "}})})" - "});"; - } - - private: - IMPLEMENT_REFCOUNTING(SyncStorageRemoveTestHandler); - DISALLOW_COPY_AND_ASSIGN(SyncStorageRemoveTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_MINIMAL(SyncStorageRemove, SyncStorageRemoveTestHandler) - -namespace { - -// Test for chrome.storage.sync.clear(function callback) -class SyncStorageClearTestHandler : public StorageTestHandler { - public: - explicit SyncStorageClearTestHandler(RequestContextType request_context_type) - : StorageTestHandler(request_context_type) {} - - protected: - std::string GetStorageApiJS() const override { - return "var value1Cleared = false;" - "var value2Cleared = false;" - - "function checkCleared() {" - "if (value1Cleared && value2Cleared) {" + - GetMessageJS(kSuccessMessage) + - "}}" - - "chrome.storage.sync.set({\"sync_key_4\": \"sync_value_4\"," - "\"sync_key_5\": \"sync_value_5\"}, function() {" - "chrome.storage.sync.clear(function () {" - - "chrome.storage.sync.get(\"sync_key_4\", function(items) {" - "if (items[\"sync_key_4\"] == undefined) {" - "value1Cleared = true;" - "checkCleared();" - "}});" - - "chrome.storage.sync.get(\"sync_key_5\", function(items) {" - "if (items[\"sync_key_5\"] == undefined) {" - "value2Cleared = true;" - "checkCleared();" - "}});" - - "})});"; - } - - private: - IMPLEMENT_REFCOUNTING(SyncStorageClearTestHandler); - DISALLOW_COPY_AND_ASSIGN(SyncStorageClearTestHandler); -}; -} // namespace - -STORAGE_TEST_GROUP_MINIMAL(SyncStorageClear, SyncStorageClearTestHandler) diff --git a/tests/ceftests/extensions/chrome_tabs_unittest.cc b/tests/ceftests/extensions/chrome_tabs_unittest.cc deleted file mode 100644 index 3649a442e..000000000 --- a/tests/ceftests/extensions/chrome_tabs_unittest.cc +++ /dev/null @@ -1,1215 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include - -#include "include/cef_parser.h" -#include "tests/ceftests/extensions/extension_test_handler.h" -#include "tests/ceftests/test_util.h" -#include "tests/shared/browser/extension_util.h" - -#define TABS_TEST_GROUP_ALL(name, test_class) \ - EXTENSION_TEST_GROUP_ALL(ChromeTabs##name, test_class) -#define TABS_TEST_GROUP_MINIMAL(name, test_class) \ - EXTENSION_TEST_GROUP_MINIMAL(ChromeTabs##name, test_class) - -namespace { - -const char kMainBrowserURL[] = "https://test-extensions.com/chrome-tabs"; -const char kExtensionPath[] = "tabs-extension"; -const char kSuccessMessage[] = "success"; - -// Base class for testing chrome.tabs methods. -// See https://developer.chrome.com/extensions/tabs -class TabsTestHandler : public ExtensionTestHandler { - public: - explicit TabsTestHandler(RequestContextType request_context_type) - : ExtensionTestHandler(request_context_type) {} - - // CefExtensionHandler methods: - void OnExtensionLoaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_FALSE(got_extension_loaded_); - got_extension_loaded_.yes(); - - // Verify |extension| contents. - EXPECT_FALSE(extension->GetIdentifier().empty()); - EXPECT_STREQ(("extensions/" + std::string(kExtensionPath)).c_str(), - client::extension_util::GetInternalExtensionResourcePath( - extension->GetPath()) - .c_str()); - TestDictionaryEqual(CreateManifest(), extension->GetManifest()); - - EXPECT_FALSE(extension_); - extension_ = extension; - - if (create_main_browser_first_) { - CreateBrowserForExtensionIfReady(); - } else { - CreateBrowserForExtension(); - } - } - - void OnExtensionUnloaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension_); - EXPECT_TRUE(extension_->IsSame(extension)); - EXPECT_FALSE(got_extension_unloaded_); - got_extension_unloaded_.yes(); - extension_ = nullptr; - - // Execute asynchronously so call stacks have a chance to unwind. - // Will close the browser windows. - CefPostTask(TID_UI, base::BindOnce(&TabsTestHandler::DestroyTest, this)); - } - - CefRefPtr GetActiveBrowser(CefRefPtr extension, - CefRefPtr browser, - bool include_incognito) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension_); - EXPECT_TRUE(extension_->IsSame(extension)); - EXPECT_TRUE(main_browser_); - - EXPECT_LE(got_get_active_browser_count_, expected_api_call_count_); - got_get_active_browser_count_++; - - // Tabs APIs will operate on the main browser. - return main_browser_; - } - - bool CanAccessBrowser(CefRefPtr extension, - CefRefPtr browser, - bool include_incognito, - CefRefPtr target_browser) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension_); - EXPECT_TRUE(extension_->IsSame(extension)); - EXPECT_TRUE(main_browser_); - EXPECT_TRUE(main_browser_->IsSame(target_browser)); - - EXPECT_LE(got_can_access_browser_count_, expected_api_call_count_); - got_can_access_browser_count_++; - - return true; - } - - // CefLoadHandler methods: - void OnLoadingStateChange(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) override { - if (isLoading) { - // Keep a reference to both browsers. - if (browser->GetHost()->GetExtension()) { - EXPECT_FALSE(extension_browser_); - extension_browser_ = browser; - } else { - EXPECT_FALSE(main_browser_); - main_browser_ = browser; - } - } else { - const std::string& url = browser->GetMainFrame()->GetURL(); - if (browser->GetHost()->GetExtension()) { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_STREQ(extension_url_.c_str(), url.c_str()); - } else { - EXPECT_TRUE(browser->IsSame(main_browser_)); - EXPECT_STREQ(kMainBrowserURL, url.c_str()); - } - } - } - - // CefResourceRequestHandler methods: - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - const std::string& url = request->GetURL(); - if (url == kMainBrowserURL) { - EXPECT_TRUE(browser->IsSame(main_browser_)); - EXPECT_FALSE(got_main_url_request_); - got_main_url_request_.yes(); - } else if (url == extension_url_) { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_FALSE(got_extension_url_request_); - got_extension_url_request_.yes(); - } - - // Handle the resource request. - return RoutingTestHandler::GetResourceHandler(browser, frame, request); - } - - protected: - void OnAddMainBrowserResources() override { - AddResource(kMainBrowserURL, GetMainBrowserHTML(), "text/html"); - } - - void OnCreateMainBrowser() override { - CreateBrowser(kMainBrowserURL, request_context()); - } - - void OnLoadExtensions() override { - LoadExtension(kExtensionPath, CreateManifest()); - } - - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - if (message == "main_onload") { - // From body onLoad in the main browser. - EXPECT_TRUE(browser->IsSame(main_browser_)); - EXPECT_FALSE(got_main_body_onload_); - got_main_body_onload_.yes(); - if (create_main_browser_first_) { - CreateBrowserForExtensionIfReady(); - } - TriggerTabsApiJSFunctionIfReady(); - return true; - } - if (message == "extension_onload") { - // From body onLoad in the extension browser. - EXPECT_TRUE(browser->IsSame(extension_browser_)); - EXPECT_FALSE(got_extension_body_onload_); - got_extension_body_onload_.yes(); - TriggerTabsApiJSFunctionIfReady(); - return true; - } - - // The success message usually orginates from the logic in - // GetMainBrowserSuccessHEAD/BODY(). It may occasionally originate from the - // extension browser if we don't know how to detect success in the main - // browser. - if (expect_success_in_main_browser_) { - EXPECT_TRUE(browser->IsSame(main_browser_)); - } else { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - } - EXPECT_FALSE(got_success_message_); - got_success_message_.yes(); - EXPECT_STREQ(kSuccessMessage, message.c_str()); - TriggerDestroyTest(); - return true; - } - - void OnDestroyTest() override { - main_browser_ = nullptr; - extension_browser_ = nullptr; - - EXPECT_TRUE(got_extension_loaded_); - EXPECT_TRUE(got_main_url_request_); - EXPECT_TRUE(got_extension_url_request_); - EXPECT_TRUE(got_main_body_onload_); - EXPECT_TRUE(got_extension_body_onload_); - EXPECT_TRUE(got_trigger_api_function_); - EXPECT_TRUE(got_success_message_); - EXPECT_TRUE(got_extension_unloaded_); - - if (expect_get_active_browser_) { - EXPECT_EQ(expected_api_call_count_, got_get_active_browser_count_); - EXPECT_EQ(0, got_can_access_browser_count_); - } else { - EXPECT_EQ(0, got_get_active_browser_count_); - EXPECT_EQ(expected_api_call_count_, got_can_access_browser_count_); - } - } - - // Create a manifest that grants access to the tabs API. - virtual CefRefPtr CreateManifest() const { - ApiPermissionsList api_permissions; - api_permissions.push_back("tabs"); - return CreateDefaultManifest(api_permissions); - } - - // Add resources in the extension browser. - virtual void OnAddExtensionResources(const std::string& origin) { - extension_url_ = origin + "extension.html"; - AddResource(extension_url_, GetExtensionHTML(), "text/html"); - } - - // Returns the target tabId (null, or value >= 0). - virtual std::string GetTargetTabId() const { return "null"; } - - // Returns the logic in the main browser that triggers on success. It should - // execute GetMessageJS(kSuccessMessage). - virtual std::string GetMainBrowserSuccessHEAD() const { - return std::string(); - } - virtual std::string GetMainBrowserSuccessBODY() const { - return std::string(); - } - - // Returns the HTML that will be loaded in the main browser. - virtual std::string GetMainBrowserHTML() const { - return "" + GetMainBrowserSuccessHEAD() + - "Main" + - GetMainBrowserSuccessBODY() + ""; - } - - // Returns the chrome.tabs.* JS that is executed in the extension browser - // when the triggerTabsApi() JS function is called. - virtual std::string GetTabsApiJS() const = 0; - - // Returns the JS that will be loaded in the extension browser. This - // implements the triggerTabsApi() JS function called from - // TriggerTabsApiJSFunction(). - virtual std::string GetExtensionJS() const { - return "function triggerTabsApi() {" + GetTabsApiJS() + "}"; - } - - // Returns the HTML that will be loaded in the extension browser. - virtual std::string GetExtensionHTML() const { - return "Extension"; - } - - virtual void TriggerDestroyTest() { - // Execute asynchronously so call stacks have a chance to unwind. - CefPostTask(TID_UI, base::BindOnce(&TabsTestHandler::UnloadExtension, this, - extension_)); - } - - CefRefPtr extension() const { return extension_; } - std::string extension_url() const { return extension_url_; } - CefRefPtr main_browser() const { return main_browser_; } - CefRefPtr extension_browser() const { return extension_browser_; } - - void set_create_main_browser_first(bool val) { - create_main_browser_first_ = val; - } - void set_expect_get_active_browser(bool val) { - expect_get_active_browser_ = val; - } - void set_expect_success_in_main_browser(bool val) { - expect_success_in_main_browser_ = val; - } - void set_expected_api_call_count(int val) { expected_api_call_count_ = val; } - - bool got_success_message() const { return got_success_message_; } - void set_got_success_message() { got_success_message_.yes(); } - - private: - void CreateBrowserForExtensionIfReady() { - DCHECK(create_main_browser_first_); - if (extension_ && main_browser_) { - CreateBrowserForExtension(); - } - } - - void CreateBrowserForExtension() { - const std::string& identifier = extension_->GetIdentifier(); - EXPECT_FALSE(identifier.empty()); - const std::string& origin = - client::extension_util::GetExtensionOrigin(identifier); - EXPECT_FALSE(origin.empty()); - - // Add extension resources. - OnAddExtensionResources(origin); - - // Create a browser to host the extension. - CreateBrowser(extension_url_, request_context()); - } - - void TriggerTabsApiJSFunctionIfReady() { - if (got_main_body_onload_ && got_extension_body_onload_) { - TriggerTabsApiJSFunction(); - } - } - - void TriggerTabsApiJSFunction() { - EXPECT_FALSE(got_trigger_api_function_); - got_trigger_api_function_.yes(); - - extension_browser_->GetMainFrame()->ExecuteJavaScript("triggerTabsApi();", - extension_url_, 0); - } - - // If true the main browser will be created before the extension browser. - // Otherwise the creation order is undefined. - bool create_main_browser_first_ = false; - - // If true we expect GetActiveBrowser() but not CanAccessBrowser() to be - // called. Else visa-versa. - bool expect_get_active_browser_ = true; - - // If true we expect the success message to be delivered in the main browser. - // Else expect it in the extension browser. - bool expect_success_in_main_browser_ = true; - - // Number of expected calls to GetActiveBrowser or CanAccessBrowser. This - // should match the number of calls to chrome.tabs.* API functions in the - // test. - int expected_api_call_count_ = 1; - - CefRefPtr extension_; - std::string extension_url_; - CefRefPtr main_browser_; - CefRefPtr extension_browser_; - - TrackCallback got_extension_loaded_; - TrackCallback got_main_url_request_; - TrackCallback got_extension_url_request_; - TrackCallback got_main_body_onload_; - TrackCallback got_extension_body_onload_; - TrackCallback got_trigger_api_function_; - TrackCallback got_success_message_; - TrackCallback got_extension_unloaded_; - - int got_get_active_browser_count_ = 0; - int got_can_access_browser_count_ = 0; -}; - -// -// chrome.tabs.create tests. -// - -const char kCreateBrowserURL[] = - "https://test-extensions.com/chrome-tabs-create"; -const char kTabCallbackMessage[] = "tab-callback"; -const int kCreateTabIndex = 2; - -// Class for chrome.tabs.create tests. -class CreateTestHandler : public TabsTestHandler { - public: - explicit CreateTestHandler(RequestContextType request_context_type) - : TabsTestHandler(request_context_type) {} - - bool OnBeforeBrowser(CefRefPtr extension, - CefRefPtr browser, - CefRefPtr active_browser, - int index, - const CefString& url, - bool foreground, - CefWindowInfo& windowInfo, - CefRefPtr& client, - CefBrowserSettings& settings) override { - EXPECT_TRUE(extension->IsSame(this->extension())); - EXPECT_TRUE(browser->IsSame(extension_browser())); - EXPECT_TRUE(active_browser->IsSame(main_browser())); - EXPECT_EQ(kCreateTabIndex, index); - EXPECT_STREQ(kCreateBrowserURL, url.ToString().c_str()); - EXPECT_TRUE(foreground); - EXPECT_TRUE(client); - - EXPECT_FALSE(got_on_before_browser_); - got_on_before_browser_.yes(); - - return false; - } - - void OnAddMainBrowserResources() override { - AddResource(kCreateBrowserURL, GetCreatedBrowserHTML(), "text/html"); - - TabsTestHandler::OnAddMainBrowserResources(); - } - - void OnLoadingStateChange(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) override { - if (extension_browser() && main_browser()) { - if (isLoading) { - // Keep a reference to the newly created browser. - EXPECT_FALSE(created_browser_); - created_browser_ = browser; - return; - } else { - const std::string& url = browser->GetMainFrame()->GetURL(); - if (url == kCreateBrowserURL) { - EXPECT_TRUE(browser->IsSame(created_browser_)); - return; - } - } - } - - TabsTestHandler::OnLoadingStateChange(browser, isLoading, canGoBack, - canGoForward); - } - - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - const std::string& url = request->GetURL(); - if (url == kCreateBrowserURL) { - EXPECT_TRUE(browser->IsSame(created_browser_)); - EXPECT_FALSE(got_create_browser_url_request_); - got_create_browser_url_request_.yes(); - } - - return TabsTestHandler::GetResourceHandler(browser, frame, request); - } - - protected: - std::string GetTabsApiJS() const override { - std::stringstream ss; - ss << kCreateTabIndex; - - return "chrome.tabs.create({url: \"" + std::string(kCreateBrowserURL) + - "\", index: " + ss.str() + - "}, function(tab) { window.testQuery({request:'" + - kTabCallbackMessage + ":' + JSON.stringify(tab)}); });"; - } - - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - if (message.find(kTabCallbackMessage) != std::string::npos) { - EXPECT_TRUE(browser->IsSame(extension_browser())); - EXPECT_FALSE(got_tab_callback_message_); - got_tab_callback_message_.yes(); - - // Verify the contents of the Tab object. - const std::string& json_str = - message.substr(strlen(kTabCallbackMessage) + 1); - CefRefPtr obj = CefParseJSON(json_str, JSON_PARSER_RFC); - EXPECT_TRUE(obj); - EXPECT_EQ(VTYPE_DICTIONARY, obj->GetType()); - CefRefPtr dict = obj->GetDictionary(); - - int index = dict->GetInt("index"); - EXPECT_EQ(kCreateTabIndex, index); - - int id = dict->GetInt("id"); - int windowId = dict->GetInt("windowId"); - EXPECT_EQ(created_browser_->GetIdentifier(), id); - EXPECT_EQ(created_browser_->GetIdentifier(), windowId); - - const std::string& url = dict->GetString("url"); - EXPECT_STREQ(kCreateBrowserURL, url.c_str()); - - TriggerDestroyTestIfReady(); - return true; - } else if (message == kSuccessMessage) { - // Overriding default kSuccessMessage handling. - EXPECT_TRUE(browser->IsSame(created_browser_)); - EXPECT_FALSE(got_success_message()); - set_got_success_message(); - TriggerDestroyTestIfReady(); - return true; - } - - return TabsTestHandler::OnMessage(browser, message); - } - - void OnDestroyTest() override { - created_browser_ = nullptr; - - EXPECT_TRUE(got_on_before_browser_); - EXPECT_TRUE(got_create_browser_url_request_); - EXPECT_TRUE(got_tab_callback_message_); - - TabsTestHandler::OnDestroyTest(); - } - - private: - std::string GetCreatedBrowserHTML() { - return "Created"; - } - - void TriggerDestroyTestIfReady() { - if (got_tab_callback_message_ && got_success_message()) { - TriggerDestroyTest(); - } - } - - CefRefPtr created_browser_; - - TrackCallback got_on_before_browser_; - TrackCallback got_create_browser_url_request_; - TrackCallback got_tab_callback_message_; - - IMPLEMENT_REFCOUNTING(CreateTestHandler); - DISALLOW_COPY_AND_ASSIGN(CreateTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(Create, CreateTestHandler) - -namespace { - -// -// chrome.tabs.executeScript tests. -// - -// Base class for chrome.tabs.executeScript tests. -class ExecuteScriptTestHandler : public TabsTestHandler { - public: - explicit ExecuteScriptTestHandler(RequestContextType request_context_type) - : TabsTestHandler(request_context_type) {} - - protected: - std::string GetMainBrowserSuccessHEAD() const override { - return ""; - } - - // Returns the code that will be injected as a content script. - virtual std::string GetContentScriptJS() const { - // Execute the onTrigger() JS function. - return "var s = document.createElement('script');" - "s.textContent = 'onTrigger();';" - "document.head.appendChild(s);"; - } - - std::string GetTabsApiJS() const override { - return "chrome.tabs.executeScript(" + GetTargetTabId() + ", {code:\"" + - GetContentScriptJS() + "\"});"; - } -}; - -// Test for chrome.tabs.executeScript with a null tabId value. -class ExecuteScriptNullTabTestHandler : public ExecuteScriptTestHandler { - public: - explicit ExecuteScriptNullTabTestHandler( - RequestContextType request_context_type) - : ExecuteScriptTestHandler(request_context_type) {} - - private: - IMPLEMENT_REFCOUNTING(ExecuteScriptNullTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(ExecuteScriptNullTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(ExecuteScriptNullTab, ExecuteScriptNullTabTestHandler) - -namespace { - -// Test for chrome.tabs.executeScript with an explicit tabId value. -class ExecuteScriptExplicitTabTestHandler : public ExecuteScriptTestHandler { - public: - explicit ExecuteScriptExplicitTabTestHandler( - RequestContextType request_context_type) - : ExecuteScriptTestHandler(request_context_type) { - // Create the main browser first so we can retrieve the id. - set_create_main_browser_first(true); - // When a tabId is specified we should get a call to CanAccessBrowser - // instead of GetActiveBrowser. - set_expect_get_active_browser(false); - } - - protected: - std::string GetTargetTabId() const override { - DCHECK(main_browser()); - std::stringstream ss; - ss << main_browser()->GetIdentifier(); - return ss.str(); - } - - private: - IMPLEMENT_REFCOUNTING(ExecuteScriptExplicitTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(ExecuteScriptExplicitTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(ExecuteScriptExplicitTab, - ExecuteScriptExplicitTabTestHandler) - -namespace { - -// Test for chrome.tabs.executeScript with a file argument loading a content -// script. -class ExecuteScriptFileTestHandler : public ExecuteScriptTestHandler { - public: - explicit ExecuteScriptFileTestHandler(RequestContextType request_context_type) - : ExecuteScriptTestHandler(request_context_type) {} - - // CefExtensionHandler methods: - bool GetExtensionResource( - CefRefPtr extension, - CefRefPtr browser, - const CefString& file, - CefRefPtr callback) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(this->extension()); - EXPECT_TRUE(this->extension()->IsSame(extension)); - - if (file == "script.js") { - EXPECT_FALSE(got_get_extension_resource_); - got_get_extension_resource_.yes(); - - const std::string& content = GetContentScriptJS(); - CefRefPtr stream = CefStreamReader::CreateForData( - const_cast(content.data()), content.size()); - callback->Continue(stream); - return true; - } - - EXPECT_FALSE(true); // Not reached. - return false; - } - - protected: - std::string GetTabsApiJS() const override { - return "chrome.tabs.executeScript(" + GetTargetTabId() + - ", {file:\"script.js\"});"; - } - - void OnDestroyTest() override { - ExecuteScriptTestHandler::OnDestroyTest(); - EXPECT_TRUE(got_get_extension_resource_); - } - - private: - TrackCallback got_get_extension_resource_; - - IMPLEMENT_REFCOUNTING(ExecuteScriptFileTestHandler); - DISALLOW_COPY_AND_ASSIGN(ExecuteScriptFileTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(ExecuteScriptFile, ExecuteScriptFileTestHandler) - -namespace { - -// Test for chrome.tabs.executeScript with a callback argument. -class ExecuteScriptCallbackTestHandler : public ExecuteScriptTestHandler { - public: - explicit ExecuteScriptCallbackTestHandler( - RequestContextType request_context_type) - : ExecuteScriptTestHandler(request_context_type) {} - - protected: - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - if (message == "callback") { - EXPECT_FALSE(got_callback_message_); - got_callback_message_.yes(); - EXPECT_TRUE(browser->IsSame(extension_browser())); - TriggerDestroyTest(); - return true; - } - return ExecuteScriptTestHandler::OnMessage(browser, message); - } - - std::string GetTabsApiJS() const override { - return "chrome.tabs.executeScript(" + GetTargetTabId() + ", {code:\"" + - GetContentScriptJS() + "\"}, function(results) {" + - GetMessageJS("callback") + "});"; - } - - void TriggerDestroyTest() override { - // Only destroy the test if we got both callbacks. - if (got_callback_message_ && got_success_message()) { - ExecuteScriptTestHandler::TriggerDestroyTest(); - } - } - - void OnDestroyTest() override { - ExecuteScriptTestHandler::OnDestroyTest(); - EXPECT_TRUE(got_callback_message_); - } - - private: - TrackCallback got_callback_message_; - - IMPLEMENT_REFCOUNTING(ExecuteScriptCallbackTestHandler); - DISALLOW_COPY_AND_ASSIGN(ExecuteScriptCallbackTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_MINIMAL(ExecuteScriptCallback, ExecuteScriptCallbackTestHandler) - -namespace { - -// Test for chrome.tabs.executeScript with execution occuring from a separate -// resource script. -class ExecuteScriptResourceTabTestHandler : public ExecuteScriptTestHandler { - public: - explicit ExecuteScriptResourceTabTestHandler( - RequestContextType request_context_type) - : ExecuteScriptTestHandler(request_context_type) {} - - // CefResourceRequestHandler methods: - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - const std::string& url = request->GetURL(); - if (url == resource_url_) { - EXPECT_TRUE(browser->IsSame(extension_browser())); - EXPECT_FALSE(got_resource_url_request_); - got_resource_url_request_.yes(); - } - - return ExecuteScriptTestHandler::GetResourceHandler(browser, frame, - request); - } - - protected: - void OnAddExtensionResources(const std::string& origin) override { - ExecuteScriptTestHandler::OnAddExtensionResources(origin); - resource_url_ = origin + "resource.js"; - AddResource(resource_url_, GetExtensionJS(), "text/javascript"); - } - - std::string GetExtensionHTML() const override { - return "Extension"; - } - - void OnDestroyTest() override { - ExecuteScriptTestHandler::OnDestroyTest(); - EXPECT_TRUE(got_resource_url_request_); - } - - private: - std::string resource_url_; - TrackCallback got_resource_url_request_; - - IMPLEMENT_REFCOUNTING(ExecuteScriptResourceTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(ExecuteScriptResourceTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_MINIMAL(ExecuteScriptResource, - ExecuteScriptResourceTabTestHandler) - -// -// chrome.tabs.insertCSS tests. -// - -namespace { - -// Base class for chrome.tabs.insertCSS tests. -class InsertCSSTestHandler : public TabsTestHandler { - public: - explicit InsertCSSTestHandler(RequestContextType request_context_type) - : TabsTestHandler(request_context_type) {} - - protected: - std::string GetMainBrowserSuccessBODY() const override { - // We can't use a MutationObserver here because insertCSS does not modify - // the style attribute. We could detect the change by tracking modifications - // to document.styleSheets but that's complicated. Use a simple timer loop - // implementation calling getComputedStyle instead. - return ""; - } - - // Returns the code that will be injected as a content script. - virtual std::string GetContentScriptCSS() const { - return "body{background-color:red}"; - } - - std::string GetTabsApiJS() const override { - return "chrome.tabs.insertCSS(" + GetTargetTabId() + ", {code:\"" + - GetContentScriptCSS() + "\"});"; - } -}; - -// Test for chrome.tabs.insertCSS with a null tabId value. -class InsertCSSNullTabTestHandler : public InsertCSSTestHandler { - public: - explicit InsertCSSNullTabTestHandler(RequestContextType request_context_type) - : InsertCSSTestHandler(request_context_type) {} - - private: - IMPLEMENT_REFCOUNTING(InsertCSSNullTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(InsertCSSNullTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(InsertCSSNullTab, InsertCSSNullTabTestHandler) - -namespace { - -// Test for chrome.tabs.insertCSS with an explicit tabId value. -class InsertCSSExplicitTabTestHandler : public InsertCSSTestHandler { - public: - explicit InsertCSSExplicitTabTestHandler( - RequestContextType request_context_type) - : InsertCSSTestHandler(request_context_type) { - // Create the main browser first so we can retrieve the id. - set_create_main_browser_first(true); - // When a tabId is specified we should get a call to CanAccessBrowser - // instead of GetActiveBrowser. - set_expect_get_active_browser(false); - } - - protected: - std::string GetTargetTabId() const override { - DCHECK(main_browser()); - std::stringstream ss; - ss << main_browser()->GetIdentifier(); - return ss.str(); - } - - private: - IMPLEMENT_REFCOUNTING(InsertCSSExplicitTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(InsertCSSExplicitTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(InsertCSSExplicitTab, InsertCSSExplicitTabTestHandler) - -namespace { - -// Test for chrome.tabs.insertCSS with a file argument loading a content -// script. -class InsertCSSFileTestHandler : public InsertCSSTestHandler { - public: - explicit InsertCSSFileTestHandler(RequestContextType request_context_type) - : InsertCSSTestHandler(request_context_type) {} - - // CefExtensionHandler methods: - bool GetExtensionResource( - CefRefPtr extension, - CefRefPtr browser, - const CefString& file, - CefRefPtr callback) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(this->extension()); - EXPECT_TRUE(this->extension()->IsSame(extension)); - - if (file == "script.css") { - EXPECT_FALSE(got_get_extension_resource_); - got_get_extension_resource_.yes(); - - const std::string& content = GetContentScriptCSS(); - CefRefPtr stream = CefStreamReader::CreateForData( - const_cast(content.data()), content.size()); - callback->Continue(stream); - return true; - } - - EXPECT_FALSE(true); // Not reached. - return false; - } - - protected: - std::string GetTabsApiJS() const override { - return "chrome.tabs.insertCSS(" + GetTargetTabId() + - ", {file:\"script.css\"});"; - } - - void OnDestroyTest() override { - InsertCSSTestHandler::OnDestroyTest(); - EXPECT_TRUE(got_get_extension_resource_); - } - - private: - TrackCallback got_get_extension_resource_; - - IMPLEMENT_REFCOUNTING(InsertCSSFileTestHandler); - DISALLOW_COPY_AND_ASSIGN(InsertCSSFileTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(InsertCSSFile, InsertCSSFileTestHandler) - -namespace { - -// Test for chrome.tabs.insertCSS with a callback argument. -class InsertCSSCallbackTestHandler : public InsertCSSTestHandler { - public: - explicit InsertCSSCallbackTestHandler(RequestContextType request_context_type) - : InsertCSSTestHandler(request_context_type) {} - - protected: - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - if (message == "callback") { - EXPECT_FALSE(got_callback_message_); - got_callback_message_.yes(); - EXPECT_TRUE(browser->IsSame(extension_browser())); - TriggerDestroyTest(); - return true; - } - return InsertCSSTestHandler::OnMessage(browser, message); - } - - std::string GetTabsApiJS() const override { - return "chrome.tabs.insertCSS(" + GetTargetTabId() + ", {code:\"" + - GetContentScriptCSS() + "\"}, function(results) {" + - GetMessageJS("callback") + "});"; - } - - void TriggerDestroyTest() override { - // Only destroy the test if we got both callbacks. - if (got_callback_message_ && got_success_message()) { - InsertCSSTestHandler::TriggerDestroyTest(); - } - } - - void OnDestroyTest() override { - InsertCSSTestHandler::OnDestroyTest(); - EXPECT_TRUE(got_callback_message_); - } - - private: - TrackCallback got_callback_message_; - - IMPLEMENT_REFCOUNTING(InsertCSSCallbackTestHandler); - DISALLOW_COPY_AND_ASSIGN(InsertCSSCallbackTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_MINIMAL(InsertCSSCallback, InsertCSSCallbackTestHandler) - -namespace { - -// Test for chrome.tabs.insertCSS with execution occuring from a separate -// resource script. -class InsertCSSResourceTabTestHandler : public InsertCSSTestHandler { - public: - explicit InsertCSSResourceTabTestHandler( - RequestContextType request_context_type) - : InsertCSSTestHandler(request_context_type) {} - - // CefResourceRequestHandler methods: - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - const std::string& url = request->GetURL(); - if (url == resource_url_) { - EXPECT_TRUE(browser->IsSame(extension_browser())); - EXPECT_FALSE(got_resource_url_request_); - got_resource_url_request_.yes(); - } - - return InsertCSSTestHandler::GetResourceHandler(browser, frame, request); - } - - protected: - void OnAddExtensionResources(const std::string& origin) override { - InsertCSSTestHandler::OnAddExtensionResources(origin); - resource_url_ = origin + "resource.js"; - AddResource(resource_url_, GetExtensionJS(), "text/javascript"); - } - - std::string GetExtensionHTML() const override { - return "Extension"; - } - - void OnDestroyTest() override { - InsertCSSTestHandler::OnDestroyTest(); - EXPECT_TRUE(got_resource_url_request_); - } - - private: - std::string resource_url_; - TrackCallback got_resource_url_request_; - - IMPLEMENT_REFCOUNTING(InsertCSSResourceTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(InsertCSSResourceTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_MINIMAL(InsertCSSResource, InsertCSSResourceTabTestHandler) - -// -// chrome.tabs.setZoom/getZoom tests. -// - -namespace { - -// Base class for chrome.tabs.setZoom/getZoom tests. -class ZoomTestHandler : public TabsTestHandler { - public: - explicit ZoomTestHandler(RequestContextType request_context_type) - : TabsTestHandler(request_context_type) { - // We call API functions three times in this handler. - set_expected_api_call_count(3); - } - - protected: - std::string GetMainBrowserSuccessHEAD() const override { - return ""; - } - - std::string GetMainBrowserSuccessBODY() const override { - // We can't directly detect zoom changes, so instead we look for changes - // in window.innerWidth. - return ""; - } - - std::string GetTabsApiJS() const override { - // Results in a change to window.innerWidth. - return "chrome.tabs.setZoom(" + GetTargetTabId() + ", 2.0);"; - } - - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - if (message == "restored") { - EXPECT_TRUE(browser->IsSame(extension_browser())); - EXPECT_FALSE(got_restored_message_); - got_restored_message_.yes(); - // Destroy the test for real. - TabsTestHandler::TriggerDestroyTest(); - return true; - } - return TabsTestHandler::OnMessage(browser, message); - } - - void TriggerDestroyTest() override { - // Before destroying the test we need to restore the zoom factor so that - // it doesn't persist in the RequestContext. This also tests the callback - // argument and the getZoom function so there's no need to do that - // separately. - extension_browser()->GetMainFrame()->ExecuteJavaScript( - "chrome.tabs.setZoom(" + GetTargetTabId() + ", 1.0, function() {" + - "chrome.tabs.getZoom(" + GetTargetTabId() + - ", function(zoomFactor) { if (zoomFactor == 1.0) {" + - GetMessageJS("restored") + "}})});", - extension_url(), 0); - } - - void OnDestroyTest() override { - TabsTestHandler::OnDestroyTest(); - EXPECT_TRUE(got_restored_message_); - } - - private: - TrackCallback got_restored_message_; -}; - -// Test for chrome.tabs.setZoom/getZoom with a null tabId value. -class ZoomNullTabTestHandler : public ZoomTestHandler { - public: - explicit ZoomNullTabTestHandler(RequestContextType request_context_type) - : ZoomTestHandler(request_context_type) {} - - private: - IMPLEMENT_REFCOUNTING(ZoomNullTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(ZoomNullTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(ZoomNullTab, ZoomNullTabTestHandler) - -namespace { - -// Test for chrome.tabs.setZoom/getZoom with an explicit tabId value. -class ZoomExplicitTabTestHandler : public ZoomTestHandler { - public: - explicit ZoomExplicitTabTestHandler(RequestContextType request_context_type) - : ZoomTestHandler(request_context_type) { - // Create the main browser first so we can retrieve the id. - set_create_main_browser_first(true); - // When a tabId is specified we should get a call to CanAccessBrowser - // instead of GetActiveBrowser. - set_expect_get_active_browser(false); - } - - protected: - std::string GetTargetTabId() const override { - DCHECK(main_browser()); - std::stringstream ss; - ss << main_browser()->GetIdentifier(); - return ss.str(); - } - - private: - IMPLEMENT_REFCOUNTING(ZoomExplicitTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(ZoomExplicitTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(ZoomExplicitTab, ZoomExplicitTabTestHandler) - -// -// chrome.tabs.setZoomSettings/getZoomSettings tests. -// - -namespace { - -// Base class for chrome.tabs.setZoomSettings/getZoomSettings tests. -class ZoomSettingsTestHandler : public TabsTestHandler { - public: - explicit ZoomSettingsTestHandler(RequestContextType request_context_type) - : TabsTestHandler(request_context_type) { - // We call API functions two times in this handler. - set_expected_api_call_count(2); - // Success message will be delivered in the extension browser because we - // don't know how to detect zoom settings changes in the main browser. - set_expect_success_in_main_browser(false); - } - - protected: - std::string GetTabsApiJS() const override { - // Set and restore the zoom settings. This also tests the callback argument - // and the getZoomSettings function so there's no need to do that - // separately. This is safe because zoom settings are not persisted in the - // RequestContext across navigations. - return "chrome.tabs.setZoomSettings(" + GetTargetTabId() + - ", {mode: 'manual', scope: 'per-tab'}, function() {" + - "chrome.tabs.getZoomSettings(" + GetTargetTabId() + - ", function(zoomSettings) { if (zoomSettings.mode == 'manual' " - "&& zoomSettings.scope == 'per-tab') {" + - GetMessageJS(kSuccessMessage) + "}})});"; - } -}; - -// Test for chrome.tabs.setZoomSettings/getZoomSettings with a null tabId value. -class ZoomSettingsNullTabTestHandler : public ZoomSettingsTestHandler { - public: - explicit ZoomSettingsNullTabTestHandler( - RequestContextType request_context_type) - : ZoomSettingsTestHandler(request_context_type) {} - - private: - IMPLEMENT_REFCOUNTING(ZoomSettingsNullTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(ZoomSettingsNullTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(ZoomSettingsNullTab, ZoomSettingsNullTabTestHandler) - -namespace { - -// Test for chrome.tabs.setZoomSettings/getZoomSettings with an explicit tabId -// value. -class ZoomSettingsExplicitTabTestHandler : public ZoomSettingsTestHandler { - public: - explicit ZoomSettingsExplicitTabTestHandler( - RequestContextType request_context_type) - : ZoomSettingsTestHandler(request_context_type) { - // Create the main browser first so we can retrieve the id. - set_create_main_browser_first(true); - // When a tabId is specified we should get a call to CanAccessBrowser - // instead of GetActiveBrowser. - set_expect_get_active_browser(false); - } - - protected: - std::string GetTargetTabId() const override { - DCHECK(main_browser()); - std::stringstream ss; - ss << main_browser()->GetIdentifier(); - return ss.str(); - } - - private: - IMPLEMENT_REFCOUNTING(ZoomSettingsExplicitTabTestHandler); - DISALLOW_COPY_AND_ASSIGN(ZoomSettingsExplicitTabTestHandler); -}; - -} // namespace - -TABS_TEST_GROUP_ALL(ZoomSettingsExplicitTab, ZoomSettingsExplicitTabTestHandler) diff --git a/tests/ceftests/extensions/extension_test_handler.cc b/tests/ceftests/extensions/extension_test_handler.cc deleted file mode 100644 index 6c5372bf7..000000000 --- a/tests/ceftests/extensions/extension_test_handler.cc +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include "tests/ceftests/extensions/extension_test_handler.h" - -#include "include/cef_request_context_handler.h" -#include "tests/ceftests/test_suite.h" -#include "tests/ceftests/test_util.h" - -ExtensionTestHandler::ExtensionTestHandler( - RequestContextType request_context_type) - : request_context_type_(request_context_type) { - // Verify supported flag combinations. - if (request_context_on_disk()) { - EXPECT_TRUE(request_context_is_custom()); - } - if (request_context_load_with_handler()) { - EXPECT_FALSE(request_context_load_without_handler()); - } - if (request_context_load_without_handler()) { - EXPECT_TRUE(request_context_with_handler()); - EXPECT_FALSE(request_context_load_with_handler()); - } -} - -ExtensionTestHandler::~ExtensionTestHandler() { - if (!request_context_temp_dir_.IsEmpty()) { - // Temporary directory will be deleted on shutdown. - request_context_temp_dir_.Take(); - } -} - -void ExtensionTestHandler::RunTest() { - if (create_main_browser_) { - OnAddMainBrowserResources(); - } - - CefRefPtr rc_handler; - if (request_context_with_handler()) { - class Handler : public CefRequestContextHandler { - public: - explicit Handler(ExtensionTestHandler* test_handler) - : test_handler_(test_handler) {} - - void OnRequestContextInitialized( - CefRefPtr request_context) override { - if (test_handler_->create_main_browser()) { - // Load extensions after the RequestContext has been initialized by - // creation of the main browser. - test_handler_->OnLoadExtensions(); - } - } - - private: - ExtensionTestHandler* test_handler_; - - IMPLEMENT_REFCOUNTING(Handler); - }; - rc_handler = new Handler(this); - } - - if (request_context_is_custom()) { - CefRequestContextSettings settings; - - if (request_context_on_disk()) { - // Create a new temporary directory. - EXPECT_TRUE(request_context_temp_dir_.CreateUniqueTempDirUnderPath( - CefTestSuite::GetInstance()->root_cache_path())); - CefString(&settings.cache_path) = request_context_temp_dir_.GetPath(); - } - - request_context_ = CefRequestContext::CreateContext(settings, rc_handler); - } else { - request_context_ = CefRequestContext::CreateContext( - CefRequestContext::GetGlobalContext(), rc_handler); - } - - if (request_context_load_with_handler()) { - class Handler : public CefRequestContextHandler { - public: - Handler() = default; - - private: - IMPLEMENT_REFCOUNTING(Handler); - }; - loader_request_context_ = - CefRequestContext::CreateContext(request_context_, new Handler()); - } else if (request_context_load_without_handler()) { - loader_request_context_ = - CefRequestContext::CreateContext(request_context_, nullptr); - } else { - loader_request_context_ = request_context_; - } - - if (create_main_browser_) { - OnCreateMainBrowser(); - } else { - // Creation of the extension browser will trigger initialization of the - // RequestContext, so just load the extensions now. - OnLoadExtensions(); - } - - // Time out the test after a reasonable period of time. - SetTestTimeout(); -} - -void ExtensionTestHandler::DestroyTest() { - OnDestroyTest(); - ReleaseRequestContexts(); - RoutingTestHandler::DestroyTest(); -} - -void ExtensionTestHandler::OnAfterCreated(CefRefPtr browser) { - RoutingTestHandler::OnAfterCreated(browser); - - if (create_main_browser() && !request_context_with_handler() && - GetBrowserId() == browser->GetIdentifier()) { - // When the RequestContext doesn't have a handler we won't get a - // notification for RequestContext initialization. Instead use main browser - // creation to indicate that the RequestContext has been initialized. - OnLoadExtensions(); - } -} - -void ExtensionTestHandler::OnExtensionLoadFailed(cef_errorcode_t result) { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(false); // Not reached. -} - -// CefMessageRouterBrowserSide::Handler methods: -bool ExtensionTestHandler::OnQuery(CefRefPtr browser, - CefRefPtr frame, - int64_t query_id, - const CefString& request, - bool persistent, - CefRefPtr callback) { - if (OnMessage(browser, request)) { - return true; - } - - EXPECT_FALSE(true) << "Unexpected message: " << request.ToString(); - return false; -} - -// static -CefRefPtr ExtensionTestHandler::CreateDefaultManifest( - const std::vector& api_permissions) { - CefRefPtr manifest = CefDictionaryValue::Create(); - manifest->SetString("name", "An extension"); - manifest->SetString("description", "An extension description"); - manifest->SetString("version", "1.0"); - manifest->SetInt("manifest_version", 2); - - CefRefPtr permissions = CefListValue::Create(); - permissions->SetSize(api_permissions.size() + 2); - size_t idx = 0; - for (; idx < api_permissions.size(); ++idx) { - permissions->SetString(idx, api_permissions[idx]); - } - - // Allow access to all http/https origins. - permissions->SetString(idx++, "http://*/*"); - permissions->SetString(idx++, "https://*/*"); - - manifest->SetList("permissions", permissions); - - return manifest; -} - -// static -std::string ExtensionTestHandler::GetMessageJS(const std::string& message) { - EXPECT_TRUE(!message.empty()); - return "window.testQuery({request:'" + message + "'});"; -} - -// static -void ExtensionTestHandler::VerifyExtensionInContext( - CefRefPtr extension, - CefRefPtr context, - bool has_access, - bool is_loader) { - const CefString& extension_id = extension->GetIdentifier(); - EXPECT_FALSE(extension_id.empty()); - - if (has_access) { - EXPECT_TRUE(context->DidLoadExtension(extension_id)); - EXPECT_TRUE(context->HasExtension(extension_id)); - } else { - EXPECT_FALSE(context->DidLoadExtension(extension_id)); - EXPECT_FALSE(context->HasExtension(extension_id)); - } - - CefRefPtr extension2 = context->GetExtension(extension_id); - if (has_access) { - EXPECT_TRUE(extension2); - EXPECT_TRUE(extension->IsSame(extension2)); - TestDictionaryEqual(extension->GetManifest(), extension2->GetManifest()); - } else { - EXPECT_FALSE(extension2); - } - - std::vector extension_ids; - EXPECT_TRUE(context->GetExtensions(extension_ids)); - - // Should be our test extension and possibly the builtin PDF extension if it - // has finished loading (our extension may load first if the call to - // LoadExtension initializes the request context). - bool has_extension = false; - for (const auto& i : extension_ids) { - if (i == extension_id) { - has_extension = true; - break; - } - } - if (has_access) { - EXPECT_TRUE(has_extension); - } else { - EXPECT_FALSE(has_extension); - } -} - -void ExtensionTestHandler::LoadExtension( - const std::string& extension_path, - CefRefPtr manifest) { - EXPECT_TRUE(!extension_path.empty()); - loader_request_context_->LoadExtension(extension_path, manifest, this); -} - -void ExtensionTestHandler::UnloadExtension(CefRefPtr extension) { - EXPECT_TRUE(extension); - extension->Unload(); - EXPECT_FALSE(extension->IsLoaded()); - EXPECT_FALSE(extension->GetLoaderContext()); -} - -void ExtensionTestHandler::ReleaseRequestContexts() { - request_context_ = nullptr; - loader_request_context_ = nullptr; -} diff --git a/tests/ceftests/extensions/extension_test_handler.h b/tests/ceftests/extensions/extension_test_handler.h deleted file mode 100644 index d8faa1727..000000000 --- a/tests/ceftests/extensions/extension_test_handler.h +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#ifndef CEF_TESTS_CEFTESTS_EXTENSIONS_EXTENSION_TEST_HANDLER_H_ -#define CEF_TESTS_CEFTESTS_EXTENSIONS_EXTENSION_TEST_HANDLER_H_ -#pragma once - -#include - -#include "include/cef_extension_handler.h" -#include "include/cef_values.h" -#include "include/wrapper/cef_scoped_temp_dir.h" -#include "tests/ceftests/routing_test_handler.h" -#include "tests/gtest/include/gtest/gtest.h" - -class ExtensionTestHandler : public RoutingTestHandler, - public CefExtensionHandler { - public: - // All tests must be able to run with all RequestContext combinations. See the - // EXTENSION_TEST_GROUP_* macros below. - enum RequestContextType { - // If set create a custom context. Otherwise, use the global context. - RC_TYPE_FLAG_CUSTOM = 1 << 0, - - // If set store data on disk. Otherwise, store data in memory. - // Requires RC_TYPE_FLAG_CUSTOM. - RC_TYPE_FLAG_ON_DISK = 1 << 1, - - // If set use a handler. Otherwise, don't. - RC_TYPE_FLAG_WITH_HANDLER = 1 << 2, - - // If set load extensions with a different context that shares the same - // storage but specifies a different handler. - // Excludes RC_TYPE_FLAG_LOAD_WITHOUT_HANDLER. - RC_TYPE_FLAG_LOAD_WITH_HANDLER = 1 << 3, - - // If set load extensions with a different context that shares the same - // storage but doesn't specify a handler. - // Requires RC_TYPE_FLAG_WITH_HANDLER. - // Excludes RC_TYPE_FLAG_LOAD_WITH_HANDLER. - RC_TYPE_FLAG_LOAD_WITHOUT_HANDLER = 1 << 4, - }; - - explicit ExtensionTestHandler(RequestContextType request_context_type); - ~ExtensionTestHandler() override; - - // TestHandler methods: - void RunTest() override; - void DestroyTest() override; - void OnAfterCreated(CefRefPtr browser) override; - - // CefExtensionHandler methods: - void OnExtensionLoadFailed(cef_errorcode_t result) override; - - // CefMessageRouterBrowserSide::Handler methods: - bool OnQuery(CefRefPtr browser, - CefRefPtr frame, - int64_t query_id, - const CefString& request, - bool persistent, - CefRefPtr callback) override; - - CefRefPtr request_context() const { - return request_context_; - } - CefRefPtr loader_request_context() const { - return loader_request_context_; - } - - bool request_context_is_custom() const { - return !!(request_context_type_ & RC_TYPE_FLAG_CUSTOM); - } - bool request_context_on_disk() const { - return !!(request_context_type_ & RC_TYPE_FLAG_ON_DISK); - } - bool request_context_with_handler() const { - return !!(request_context_type_ & RC_TYPE_FLAG_WITH_HANDLER); - } - bool request_context_load_with_handler() const { - return !!(request_context_type_ & RC_TYPE_FLAG_LOAD_WITH_HANDLER); - } - bool request_context_load_without_handler() const { - return !!(request_context_type_ & RC_TYPE_FLAG_LOAD_WITHOUT_HANDLER); - } - bool request_context_same_loader() const { - return !(request_context_load_with_handler() || - request_context_load_without_handler()); - } - - protected: - // Returns the default extension manifest. - typedef std::vector ApiPermissionsList; - static CefRefPtr CreateDefaultManifest( - const ApiPermissionsList& api_permissions); - - // Returns the JS code that, when executed, will deliver |message| to the - // OnMessage callback. - static std::string GetMessageJS(const std::string& message); - - // Run checks on the state of |extension| in |context|. If |has_access| is - // true then |context| is expected to have access to |extension|. If - // |is_loader| is true then |context| is expected to have loaded |extension|. - static void VerifyExtensionInContext(CefRefPtr extension, - CefRefPtr context, - bool has_access, - bool is_loader); - - // Helper for loading/unloading an extension. - void LoadExtension(const std::string& extension_path, - CefRefPtr manifest); - void UnloadExtension(CefRefPtr extension); - - // Release request contexts. This is normally called from DestroyTest(). - void ReleaseRequestContexts(); - - void set_create_main_browser(bool val) { create_main_browser_ = val; } - bool create_main_browser() const { return create_main_browser_; } - - // Called when its time to add resources for the main browser if - // |create_main_browser_| is true. - virtual void OnAddMainBrowserResources() {} - // Called when its time to create the main browser if - // |create_main_browser_| is true. - virtual void OnCreateMainBrowser() {} - - // Called when its time to load extensions. - virtual void OnLoadExtensions() = 0; - - // Called when |browser| receives |message|. Return true if the message is - // handled. The JS code that sends messages is created by GetMessageJS(). - virtual bool OnMessage(CefRefPtr browser, - const std::string& message) = 0; - - // Called to perform verification on test destruction. - virtual void OnDestroyTest() = 0; - - private: - const RequestContextType request_context_type_; - CefScopedTempDir request_context_temp_dir_; - - // Context used when creating browsers. - CefRefPtr request_context_; - - // Context used when loading extensions. - CefRefPtr loader_request_context_; - - // If true expect creation of a main browser. Default is true. - bool create_main_browser_ = true; - - DISALLOW_COPY_AND_ASSIGN(ExtensionTestHandler); -}; - -// Helper for implementing an extension test. -#define EXTENSION_TEST(name, test_class, rc_type) \ - TEST(ExtensionTest, name) { \ - CefRefPtr handler = new test_class( \ - static_cast(rc_type)); \ - handler->ExecuteTest(); \ - ReleaseAndWaitForDestructor(handler); \ - } - -// Helper for implementing extension tests that include all RequestContext -// combinations. When two or more extension tests significantly overlap in -// tested functionality the first test should use the ALL macro and the others -// should use the MINIMAL macro. -#define EXTENSION_TEST_GROUP_ALL(name, test_class) \ - EXTENSION_TEST(name##RCGlobal, test_class, 0) \ - EXTENSION_TEST(name##RCGlobalLoadWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITH_HANDLER) \ - EXTENSION_TEST(name##RCGlobalWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER) \ - EXTENSION_TEST(name##RCGlobalWithHandlerLoadWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITH_HANDLER) \ - EXTENSION_TEST(name##RCGlobalWithHandlerLoadWithoutHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITHOUT_HANDLER) \ - EXTENSION_TEST(name##RCCustomInMemory, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM) \ - EXTENSION_TEST(name##RCCustomInMemoryLoadWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITH_HANDLER) \ - EXTENSION_TEST(name##RCCustomInMemoryWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER) \ - EXTENSION_TEST(name##RCCustomInMemoryWithHandlerLoadWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITH_HANDLER) \ - EXTENSION_TEST(name##RCCustomInMemoryWithHandlerLoadWithoutHandler, \ - test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITHOUT_HANDLER) \ - EXTENSION_TEST(name##RCCustomOnDisk, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_ON_DISK) \ - EXTENSION_TEST(name##RCCustomOnDiskLoadWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_ON_DISK | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITH_HANDLER) \ - EXTENSION_TEST(name##RCCustomOnDiskWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_ON_DISK | \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER) \ - EXTENSION_TEST(name##RCCustomOnDiskWithHandlerLoadWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_ON_DISK | \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITH_HANDLER) \ - EXTENSION_TEST(name##RCCustomOnDiskWithHandlerLoadWithoutHandler, \ - test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_ON_DISK | \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER | \ - ExtensionTestHandler::RC_TYPE_FLAG_LOAD_WITHOUT_HANDLER) - -#define EXTENSION_TEST_GROUP_MINIMAL_GLOBAL(name, test_class) \ - EXTENSION_TEST(name##RCGlobal, test_class, 0) \ - EXTENSION_TEST(name##RCGlobalWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER) - -#define EXTENSION_TEST_GROUP_MINIMAL_CUSTOM(name, test_class) \ - EXTENSION_TEST(name##RCCustomInMemory, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM) \ - EXTENSION_TEST(name##RCCustomInMemoryWithHandler, test_class, \ - ExtensionTestHandler::RC_TYPE_FLAG_CUSTOM | \ - ExtensionTestHandler::RC_TYPE_FLAG_WITH_HANDLER) - -// Helper for implementing extension tests that include a minimal set of -// RequestContext combinations. This mostly just verifies that the test runs -// and doesn't leak state information in the context. -#define EXTENSION_TEST_GROUP_MINIMAL(name, test_class) \ - EXTENSION_TEST_GROUP_MINIMAL_GLOBAL(name, test_class) \ - EXTENSION_TEST_GROUP_MINIMAL_CUSTOM(name, test_class) - -#endif // CEF_TESTS_CEFTESTS_EXTENSIONS_EXTENSION_TEST_HANDLER_H_ diff --git a/tests/ceftests/extensions/view_unittest.cc b/tests/ceftests/extensions/view_unittest.cc deleted file mode 100644 index 23886a133..000000000 --- a/tests/ceftests/extensions/view_unittest.cc +++ /dev/null @@ -1,244 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include "tests/ceftests/extensions/extension_test_handler.h" -#include "tests/ceftests/test_util.h" -#include "tests/shared/browser/extension_util.h" - -namespace { - -const char kExtensionPath[] = "view-extension"; - -// Test extension load/unload. -class ViewLoadUnloadTestHandler : public ExtensionTestHandler { - public: - explicit ViewLoadUnloadTestHandler(RequestContextType request_context_type) - : ExtensionTestHandler(request_context_type) { - // Only creating the extension browser. - set_create_main_browser(false); - } - - // CefExtensionHandler methods: - void OnExtensionLoaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension->IsLoaded()); - EXPECT_TRUE(extension->GetLoaderContext()); - EXPECT_TRUE( - loader_request_context()->IsSame(extension->GetLoaderContext())); - VerifyExtension(extension); - - EXPECT_FALSE(got_loaded_); - got_loaded_.yes(); - - EXPECT_FALSE(extension_); - extension_ = extension; - - CreateBrowserForExtension(); - } - - void OnExtensionUnloaded(CefRefPtr extension) override { - EXPECT_TRUE(CefCurrentlyOn(TID_UI)); - EXPECT_TRUE(extension); - EXPECT_FALSE(extension->IsLoaded()); - EXPECT_FALSE(extension->GetLoaderContext()); - - EXPECT_FALSE(got_unloaded_); - got_unloaded_.yes(); - - EXPECT_TRUE(extension_); - EXPECT_TRUE(extension_->IsSame(extension)); - - // The extension should no longer be registered with the context. - if (loader_request_context()) { - VerifyExtensionInContext(extension, loader_request_context(), false, - true); - } - if (request_context() && !request_context_same_loader()) { - VerifyExtensionInContext(extension, request_context(), false, false); - } - - extension_ = nullptr; - - // Execute asynchronously so call stacks have a chance to unwind. - // Will close the browser windows. - CefPostTask(TID_UI, - base::BindOnce(&ViewLoadUnloadTestHandler::DestroyTest, this)); - } - - // CefLoadHandler methods: - void OnLoadingStateChange(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) override { - EXPECT_FALSE(browser->GetHost()->IsBackgroundHost()); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - if (isLoading) { - EXPECT_FALSE(extension_browser_); - extension_browser_ = browser; - } else { - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - const std::string& url = browser->GetMainFrame()->GetURL(); - EXPECT_STREQ(extension_url_.c_str(), url.c_str()); - - EXPECT_FALSE(got_load_done_); - got_load_done_.yes(); - - TriggerDestroyTestIfDone(); - } - } - - // CefResourceRequestHandler methods: - CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { - EXPECT_FALSE(browser->GetHost()->IsBackgroundHost()); - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - const std::string& url = request->GetURL(); - EXPECT_STREQ(extension_url_.c_str(), url.c_str()); - - EXPECT_FALSE(got_url_request_); - got_url_request_.yes(); - - // Handle the resource request. - return RoutingTestHandler::GetResourceHandler(browser, frame, request); - } - - protected: - void OnLoadExtensions() override { - LoadExtension(kExtensionPath, CreateManifest()); - } - - bool OnMessage(CefRefPtr browser, - const std::string& message) override { - EXPECT_FALSE(browser->GetHost()->IsBackgroundHost()); - EXPECT_STREQ("extension_onload", message.c_str()); - - CefRefPtr extension = browser->GetHost()->GetExtension(); - EXPECT_TRUE(extension); - EXPECT_TRUE(extension_->IsSame(extension)); - - EXPECT_TRUE(browser->IsSame(extension_browser_)); - - EXPECT_FALSE(got_body_onload_); - got_body_onload_.yes(); - - TriggerDestroyTestIfDone(); - return true; - } - - void OnDestroyTest() override { - extension_browser_ = nullptr; - - EXPECT_TRUE(got_loaded_); - EXPECT_TRUE(got_url_request_); - EXPECT_TRUE(got_body_onload_); - EXPECT_TRUE(got_load_done_); - EXPECT_TRUE(got_unloaded_); - } - - // Create the default manifest. - CefRefPtr CreateManifest() const { - return CreateDefaultManifest(ApiPermissionsList()); - } - - // Verify |extension| contents. - void VerifyExtension(CefRefPtr extension) const { - EXPECT_STREQ(("extensions/" + std::string(kExtensionPath)).c_str(), - client::extension_util::GetInternalExtensionResourcePath( - extension->GetPath()) - .c_str()); - - CefRefPtr expected_manifest = CreateManifest(); - TestDictionaryEqual(expected_manifest, extension->GetManifest()); - - VerifyExtensionInContext(extension, loader_request_context(), true, true); - if (!request_context_same_loader()) { - VerifyExtensionInContext(extension, request_context(), true, false); - } - } - - void CreateBrowserForExtension() { - const std::string& identifier = extension_->GetIdentifier(); - EXPECT_FALSE(identifier.empty()); - const std::string& origin = - client::extension_util::GetExtensionOrigin(identifier); - EXPECT_FALSE(origin.empty()); - - // Add extension resources. - extension_url_ = origin + "extension.html"; - AddResource(extension_url_, - "Extension", - "text/html"); - - // Create a browser to host the extension. - CreateBrowser(extension_url_, request_context()); - } - - void TriggerDestroyTestIfDone() { - if (got_body_onload_ && got_load_done_) { - TriggerDestroyTest(); - } - } - - virtual void TriggerDestroyTest() { - // Execute asynchronously so call stacks have a chance to unwind. - CefPostTask(TID_UI, - base::BindOnce(&ViewLoadUnloadTestHandler::UnloadExtension, - this, extension_)); - } - - CefRefPtr extension_; - std::string extension_url_; - CefRefPtr extension_browser_; - - TrackCallback got_loaded_; - TrackCallback got_url_request_; - TrackCallback got_body_onload_; - TrackCallback got_load_done_; - TrackCallback got_unloaded_; - - IMPLEMENT_REFCOUNTING(ViewLoadUnloadTestHandler); - DISALLOW_COPY_AND_ASSIGN(ViewLoadUnloadTestHandler); -}; - -} // namespace - -EXTENSION_TEST_GROUP_ALL(ViewLoadUnload, ViewLoadUnloadTestHandler) - -namespace { - -// Same as above but without the unload. Only do this with a custom context to -// avoid poluting the global context. -class ViewLoadNoUnloadTestHandler : public ViewLoadUnloadTestHandler { - public: - explicit ViewLoadNoUnloadTestHandler(RequestContextType request_context_type) - : ViewLoadUnloadTestHandler(request_context_type) {} - - protected: - void TriggerDestroyTest() override { - // Release everything that references the request context. This should - // trigger unload of the extension. - CloseBrowser(extension_browser_, false); - extension_browser_ = nullptr; - ReleaseRequestContexts(); - } -}; - -} // namespace - -EXTENSION_TEST_GROUP_MINIMAL_CUSTOM(ViewLoadNoUnload, - ViewLoadNoUnloadTestHandler) diff --git a/tests/shared/browser/extension_util.cc b/tests/shared/browser/extension_util.cc deleted file mode 100644 index 3d7f17d0d..000000000 --- a/tests/shared/browser/extension_util.cc +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include "tests/shared/browser/extension_util.h" - -#include -#include - -#include "include/base/cef_callback.h" -#include "include/cef_parser.h" -#include "include/cef_path_util.h" -#include "include/wrapper/cef_closure_task.h" -#include "tests/shared/browser/file_util.h" -#include "tests/shared/browser/resource_util.h" -#include "tests/shared/common/string_util.h" - -namespace client::extension_util { - -namespace { - -std::string GetResourcesPath() { - CefString resources_dir; - if (CefGetPath(PK_DIR_RESOURCES, resources_dir) && !resources_dir.empty()) { - return resources_dir.ToString() + file_util::kPathSep; - } - return std::string(); -} - -// Internal extension paths may be prefixed with PK_DIR_RESOURCES and always -// use forward slash as path separator. -std::string GetInternalPath(const std::string& extension_path) { - std::string resources_path_lower = GetResourcesPath(); - std::string extension_path_lower = extension_path; - -#if defined(OS_WIN) - // Convert to lower-case, since Windows paths are case-insensitive. - resources_path_lower = AsciiStrToLower(resources_path_lower); - extension_path_lower = AsciiStrToLower(extension_path_lower); -#endif - - std::string internal_path; - if (!resources_path_lower.empty() && - extension_path_lower.find(resources_path_lower) == 0U) { - internal_path = extension_path.substr(resources_path_lower.size()); - } else { - internal_path = extension_path; - } - -#if defined(OS_WIN) - // Normalize path separators. - std::replace(internal_path.begin(), internal_path.end(), '\\', '/'); -#endif - - return internal_path; -} - -using ManifestCallback = - base::OnceCallback /*manifest*/)>; - -void RunManifestCallback(ManifestCallback callback, - CefRefPtr manifest) { - if (!CefCurrentlyOn(TID_UI)) { - // Execute on the browser UI thread. - CefPostTask(TID_UI, base::BindOnce(std::move(callback), manifest)); - return; - } - std::move(callback).Run(manifest); -} - -// Asynchronously reads the manifest and executes |callback| on the UI thread. -void GetInternalManifest(const std::string& extension_path, - ManifestCallback callback) { - if (!CefCurrentlyOn(TID_FILE_USER_BLOCKING)) { - // Execute on the browser FILE thread. - CefPostTask(TID_FILE_USER_BLOCKING, - base::BindOnce(GetInternalManifest, extension_path, - std::move(callback))); - return; - } - - const std::string& manifest_path = GetInternalExtensionResourcePath( - file_util::JoinPath(extension_path, "manifest.json")); - std::string manifest_contents; - if (!LoadBinaryResource(manifest_path.c_str(), manifest_contents) || - manifest_contents.empty()) { - LOG(ERROR) << "Failed to load manifest from " << manifest_path; - RunManifestCallback(std::move(callback), nullptr); - return; - } - - CefString error_msg; - CefRefPtr value = - CefParseJSONAndReturnError(manifest_contents, JSON_PARSER_RFC, error_msg); - if (!value || value->GetType() != VTYPE_DICTIONARY) { - if (error_msg.empty()) { - error_msg = "Incorrectly formatted dictionary contents."; - } - LOG(ERROR) << "Failed to parse manifest from " << manifest_path << "; " - << error_msg.ToString(); - RunManifestCallback(std::move(callback), nullptr); - return; - } - - RunManifestCallback(std::move(callback), value->GetDictionary()); -} - -void LoadExtensionWithManifest(CefRefPtr request_context, - const std::string& extension_path, - CefRefPtr handler, - CefRefPtr manifest) { - CEF_REQUIRE_UI_THREAD(); - - // Load the extension internally. Resource requests will be handled via - // AddInternalExtensionToResourceManager. - request_context->LoadExtension(extension_path, manifest, handler); -} - -} // namespace - -bool IsInternalExtension(const std::string& extension_path) { - // List of internally handled extensions. - static const char* extensions[] = {"set_page_color"}; - - const std::string& internal_path = GetInternalPath(extension_path); - for (auto& i : extensions) { - // Exact match or first directory component. - const std::string& extension = i; - if (internal_path == extension || - internal_path.find(extension + '/') == 0) { - return true; - } - } - - return false; -} - -std::string GetInternalExtensionResourcePath( - const std::string& extension_path) { - return "extensions/" + GetInternalPath(extension_path); -} - -std::string GetExtensionResourcePath(const std::string& extension_path, - bool* internal) { - const bool is_internal = IsInternalExtension(extension_path); - if (internal) { - *internal = is_internal; - } - if (is_internal) { - return GetInternalExtensionResourcePath(extension_path); - } - return extension_path; -} - -bool GetExtensionResourceContents(const std::string& extension_path, - std::string& contents) { - CEF_REQUIRE_FILE_USER_BLOCKING_THREAD(); - - if (IsInternalExtension(extension_path)) { - const std::string& contents_path = - GetInternalExtensionResourcePath(extension_path); - return LoadBinaryResource(contents_path.c_str(), contents); - } - - return file_util::ReadFileToString(extension_path, &contents); -} - -void LoadExtension(CefRefPtr request_context, - const std::string& extension_path, - CefRefPtr handler) { - if (!CefCurrentlyOn(TID_UI)) { - // Execute on the browser UI thread. - CefPostTask(TID_UI, base::BindOnce(LoadExtension, request_context, - extension_path, handler)); - return; - } - - if (IsInternalExtension(extension_path)) { - // Read the extension manifest and load asynchronously. - GetInternalManifest( - extension_path, - base::BindOnce(LoadExtensionWithManifest, request_context, - extension_path, handler)); - } else { - // Load the extension from disk. - request_context->LoadExtension(extension_path, nullptr, handler); - } -} - -void AddInternalExtensionToResourceManager( - CefRefPtr extension, - CefRefPtr resource_manager) { - DCHECK(IsInternalExtension(extension->GetPath())); - - if (!CefCurrentlyOn(TID_IO)) { - // Execute on the browser IO thread. - CefPostTask(TID_IO, base::BindOnce(AddInternalExtensionToResourceManager, - extension, resource_manager)); - return; - } - - const std::string& origin = GetExtensionOrigin(extension->GetIdentifier()); - const std::string& resource_path = - GetInternalExtensionResourcePath(extension->GetPath()); - -// Add provider for bundled resource files. -#if defined(OS_WIN) - // Read resources from the binary. - resource_manager->AddProvider( - CreateBinaryResourceProvider(origin, resource_path), 50, std::string()); -#elif defined(OS_POSIX) - // Read resources from a directory on disk. - std::string resource_dir; - if (GetResourceDir(resource_dir)) { - resource_dir += "/" + resource_path; - resource_manager->AddDirectoryProvider(origin, resource_dir, 50, - std::string()); - } -#endif -} - -std::string GetExtensionOrigin(const std::string& extension_id) { - return "chrome-extension://" + extension_id + "/"; -} - -std::string GetExtensionURL(CefRefPtr extension) { - CefRefPtr browser_action = - extension->GetManifest()->GetDictionary("browser_action"); - if (browser_action) { - const std::string& default_popup = - browser_action->GetString("default_popup"); - if (!default_popup.empty()) { - return GetExtensionOrigin(extension->GetIdentifier()) + default_popup; - } - } - - return std::string(); -} - -std::string GetExtensionIconPath(CefRefPtr extension, - bool* internal) { - CefRefPtr browser_action = - extension->GetManifest()->GetDictionary("browser_action"); - if (browser_action) { - const std::string& default_icon = browser_action->GetString("default_icon"); - if (!default_icon.empty()) { - return GetExtensionResourcePath( - file_util::JoinPath(extension->GetPath(), default_icon), internal); - } - } - - return std::string(); -} - -} // namespace client::extension_util diff --git a/tests/shared/browser/extension_util.h b/tests/shared/browser/extension_util.h deleted file mode 100644 index b7a6662bd..000000000 --- a/tests/shared/browser/extension_util.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#ifndef CEF_TESTS_CEFCLIENT_BROWSER_EXTENSION_UTIL_H_ -#define CEF_TESTS_CEFCLIENT_BROWSER_EXTENSION_UTIL_H_ -#pragma once - -#include - -#include "include/cef_extension.h" -#include "include/cef_extension_handler.h" -#include "include/wrapper/cef_resource_manager.h" - -namespace client::extension_util { - -// Returns true if |extension_path| can be handled internally via -// LoadBinaryResource. This checks a hard-coded list of allowed extension path -// components. -bool IsInternalExtension(const std::string& extension_path); - -// Returns the path relative to the resource directory after removing the -// PK_DIR_RESOURCES prefix. This will be the relative path expected by -// LoadBinaryResource (uses '/' as path separator on all platforms). Only call -// this method for internal extensions, either when IsInternalExtension returns -// true or when the extension is handled internally through some means other -// than LoadBinaryResource. Use GetExtensionResourcePath instead if you are -// unsure whether the extension is internal or external. -std::string GetInternalExtensionResourcePath(const std::string& extension_path); - -// Returns the resource path for |extension_path|. For external extensions this -// will be the full file path on disk. For internal extensions this will be the -// relative path expected by LoadBinaryResource (uses '/' as path separator on -// all platforms). Internal extensions must be on the hard-coded list enforced -// by IsInternalExtension. If |internal| is non-nullptr it will be set to true -// if the extension is handled internally. -std::string GetExtensionResourcePath(const std::string& extension_path, - bool* internal); - -// Read the contents of |extension_path| into |contents|. For external -// extensions this will read the file from disk. For internal extensions this -// will call LoadBinaryResource. Internal extensions must be on the hard-coded -// list enforced by IsInternalExtension. Returns true on success. Must be -// called on the FILE thread. -bool GetExtensionResourceContents(const std::string& extension_path, - std::string& contents); - -// Load |extension_path| in |request_context|. May be an internal or external -// extension. Internal extensions must be on the hard-coded list enforced by -// IsInternalExtension. -void LoadExtension(CefRefPtr request_context, - const std::string& extension_path, - CefRefPtr handler); - -// Register an internal handler for extension resources. Internal extensions -// must be on the hard-coded list enforced by IsInternalExtension. -void AddInternalExtensionToResourceManager( - CefRefPtr extension, - CefRefPtr resource_manager); - -// Returns the URL origin for |extension_id|. -std::string GetExtensionOrigin(const std::string& extension_id); - -// Parse browser_action manifest values as defined at -// https://developer.chrome.com/extensions/browserAction - -// Look for a browser_action.default_popup manifest value. -std::string GetExtensionURL(CefRefPtr extension); - -// Look for a browser_action.default_icon manifest value and return the resource -// path. If |internal| is non-nullptr it will be set to true if the extension is -// handled internally. -std::string GetExtensionIconPath(CefRefPtr extension, - bool* internal); - -} // namespace client::extension_util - -#endif // CEF_TESTS_CEFCLIENT_BROWSER_EXTENSION_UTIL_H_ diff --git a/tests/shared/common/client_switches.cc b/tests/shared/common/client_switches.cc index cfddbe173..37434a2d6 100644 --- a/tests/shared/common/client_switches.cc +++ b/tests/shared/common/client_switches.cc @@ -43,9 +43,6 @@ const char kAlwaysOnTop[] = "always-on-top"; const char kHideTopMenu[] = "hide-top-menu"; const char kSslClientCertificate[] = "ssl-client-certificate"; const char kCRLSetsPath[] = "crl-sets-path"; -#if !defined(DISABLE_ALLOY_BOOTSTRAP) -const char kLoadExtension[] = "load-extension"; -#endif const char kNoActivate[] = "no-activate"; #if !defined(DISABLE_ALLOY_BOOTSTRAP) const char kEnableChromeRuntime[] = "enable-chrome-runtime"; diff --git a/tests/shared/common/client_switches.h b/tests/shared/common/client_switches.h index 055bf1e99..30eec8911 100644 --- a/tests/shared/common/client_switches.h +++ b/tests/shared/common/client_switches.h @@ -37,9 +37,6 @@ extern const char kAlwaysOnTop[]; extern const char kHideTopMenu[]; extern const char kSslClientCertificate[]; extern const char kCRLSetsPath[]; -#if !defined(DISABLE_ALLOY_BOOTSTRAP) -extern const char kLoadExtension[]; -#endif extern const char kNoActivate[]; #if !defined(DISABLE_ALLOY_BOOTSTRAP) extern const char kEnableChromeRuntime[]; diff --git a/tools/make_distrib.py b/tools/make_distrib.py index d76ca2bbe..c97c24e69 100644 --- a/tools/make_distrib.py +++ b/tools/make_distrib.py @@ -822,8 +822,6 @@ if mode == 'standard': 'tests/cefclient/', cefclient_dir, options.quiet) transfer_gypi_files(cef_dir, cef_paths2['cefclient_sources_resources'], \ 'tests/cefclient/', cefclient_dir, options.quiet) - transfer_gypi_files(cef_dir, cef_paths2['cefclient_sources_resources_extensions_set_page_color'], \ - 'tests/cefclient/', cefclient_dir, options.quiet) # transfer common cefsimple files transfer_gypi_files(cef_dir, cef_paths2['cefsimple_sources_common'], \