| Index: chrome/browser/extensions/api/tabs/tabs_test.cc
|
| diff --git a/chrome/browser/extensions/api/tabs/tabs_test.cc b/chrome/browser/extensions/api/tabs/tabs_test.cc
|
| index 6bb27097ff2a4817d707f5c5335dbab8fbc120f9..29c10b39280ea8d370ece5911bbfe63979f56228 100644
|
| --- a/chrome/browser/extensions/api/tabs/tabs_test.cc
|
| +++ b/chrome/browser/extensions/api/tabs/tabs_test.cc
|
| @@ -13,6 +13,7 @@
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/values.h"
|
| +#include "chrome/browser/apps/app_browsertest_util.h"
|
| #include "chrome/browser/devtools/devtools_window_testing.h"
|
| #include "chrome/browser/extensions/api/tabs/tabs_api.h"
|
| #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
|
| @@ -26,6 +27,7 @@
|
| #include "chrome/browser/ui/browser_commands.h"
|
| #include "chrome/browser/ui/browser_window.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/browser/ui/views/frame/browser_view.h"
|
| #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| #include "content/public/browser/browser_context.h"
|
| @@ -33,12 +35,17 @@
|
| #include "content/public/common/page_zoom.h"
|
| #include "content/public/common/url_constants.h"
|
| #include "extensions/browser/api_test_utils.h"
|
| +#include "extensions/browser/app_window/app_window.h"
|
| +#include "extensions/browser/app_window/app_window_registry.h"
|
| +#include "extensions/browser/app_window/native_app_window.h"
|
| #include "extensions/common/manifest_constants.h"
|
| #include "extensions/common/test_util.h"
|
| #include "extensions/test/extension_test_message_listener.h"
|
| #include "extensions/test/result_catcher.h"
|
| #include "net/test/spawned_test_server/spawned_test_server.h"
|
| #include "ui/gfx/geometry/rect.h"
|
| +#include "ui/views/widget/widget.h"
|
| +#include "ui/views/widget/widget_observer.h"
|
|
|
| namespace extensions {
|
|
|
| @@ -46,7 +53,7 @@ namespace keys = tabs_constants;
|
| namespace utils = extension_function_test_utils;
|
|
|
| namespace {
|
| -using ExtensionTabsTest = ExtensionApiTest;
|
| +using ExtensionTabsTest = PlatformAppBrowserTest;
|
|
|
| class ExtensionWindowCreateTest : public InProcessBrowserTest {
|
| public:
|
| @@ -84,26 +91,6 @@ int GetWindowId(base::DictionaryValue* window) {
|
|
|
| } // namespace
|
|
|
| -IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, WindowTypes) {
|
| - Browser* normal_browser = new Browser(Browser::CreateParams(
|
| - browser()->profile(), browser()->host_desktop_type()));
|
| - EXPECT_EQ(keys::kWindowTypeValueNormal,
|
| - normal_browser->extension_window_controller()->GetWindowTypeText());
|
| -
|
| - Browser* popup_browser = new Browser(
|
| - Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(),
|
| - browser()->host_desktop_type()));
|
| - EXPECT_EQ(keys::kWindowTypeValuePopup,
|
| - popup_browser->extension_window_controller()->GetWindowTypeText());
|
| -
|
| - DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| - browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
|
| - EXPECT_EQ(keys::kWindowTypeValueDevTools, DevToolsWindowTesting::Get(devtools)
|
| - ->browser()
|
| - ->extension_window_controller()
|
| - ->GetWindowTypeText());
|
| -}
|
| -
|
| IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) {
|
| int window_id = ExtensionTabUtil::GetWindowId(browser());
|
|
|
| @@ -203,6 +190,22 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) {
|
| browser(),
|
| utils::INCLUDE_INCOGNITO)));
|
| EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "incognito"));
|
| +
|
| + // DevTools window.
|
| + DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| + browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
|
| +
|
| + function = new WindowsGetFunction();
|
| + function->set_extension(extension.get());
|
| + result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
|
| + function.get(),
|
| + base::StringPrintf("[%u, {\"windowTypes\": [\"devtools\"]}]",
|
| + ExtensionTabUtil::GetWindowId(
|
| + DevToolsWindowTesting::Get(devtools)->browser())),
|
| + browser(), utils::INCLUDE_INCOGNITO)));
|
| + EXPECT_EQ("devtools", api_test_utils::GetString(result.get(), "type"));
|
| +
|
| + DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) {
|
| @@ -257,7 +260,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) {
|
| window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser));
|
| }
|
|
|
| - // Undocked DevTools window should not be accessible.
|
| + // Application windows should not be accessible, unless allWindowTypes is set
|
| + // to true.
|
| + AppWindow* app_window = CreateTestAppWindow("{}");
|
| +
|
| + // Undocked DevTools window should not be accessible, unless allWindowTypes is
|
| + // set to true.
|
| DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
|
|
|
| @@ -270,8 +278,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) {
|
| browser())));
|
|
|
| base::ListValue* windows = result.get();
|
| - EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
|
| - for (size_t i = 0; i < NUM_WINDOWS; ++i) {
|
| + EXPECT_EQ(window_ids.size(), windows->GetSize());
|
| + for (size_t i = 0; i < windows->GetSize(); ++i) {
|
| base::DictionaryValue* result_window = nullptr;
|
| EXPECT_TRUE(windows->GetDictionary(i, &result_window));
|
| result_ids.insert(GetWindowId(result_window));
|
| @@ -292,7 +300,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) {
|
| browser())));
|
|
|
| windows = result.get();
|
| - EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
|
| + EXPECT_EQ(window_ids.size(), windows->GetSize());
|
| for (size_t i = 0; i < windows->GetSize(); ++i) {
|
| base::DictionaryValue* result_window = nullptr;
|
| EXPECT_TRUE(windows->GetDictionary(i, &result_window));
|
| @@ -302,10 +310,88 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) {
|
| base::ListValue* tabs = nullptr;
|
| EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs));
|
| }
|
| - // The returned ids should contain all the current browser instance ids.
|
| + // The returned ids should contain all the current app, browser and
|
| + // devtools instance ids.
|
| EXPECT_EQ(window_ids, result_ids);
|
|
|
| DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
|
| +
|
| + CloseAppWindow(app_window);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindowsAllTypes) {
|
| + const size_t NUM_WINDOWS = 5;
|
| + std::set<int> window_ids;
|
| + std::set<int> result_ids;
|
| + window_ids.insert(ExtensionTabUtil::GetWindowId(browser()));
|
| +
|
| + for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) {
|
| + Browser* new_browser = CreateBrowser(browser()->profile());
|
| + window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser));
|
| + }
|
| +
|
| + // Application windows should be accessible.
|
| + AppWindow* app_window = CreateTestAppWindow("{}");
|
| + window_ids.insert(app_window->session_id().id());
|
| +
|
| + // Undocked DevTools window should be accessible too.
|
| + DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| + browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
|
| + window_ids.insert(ExtensionTabUtil::GetWindowId(
|
| + DevToolsWindowTesting::Get(devtools)->browser()));
|
| +
|
| + scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction();
|
| + scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
|
| + function->set_extension(extension.get());
|
| + scoped_ptr<base::ListValue> result(
|
| + utils::ToList(utils::RunFunctionAndReturnSingleResult(
|
| + function.get(),
|
| + "[{\"windowTypes\": [\"app\", \"devtools\", \"normal\", \"panel\", "
|
| + "\"popup\"]}]",
|
| + browser())));
|
| +
|
| + base::ListValue* windows = result.get();
|
| + EXPECT_EQ(window_ids.size(), windows->GetSize());
|
| + for (size_t i = 0; i < windows->GetSize(); ++i) {
|
| + base::DictionaryValue* result_window = nullptr;
|
| + EXPECT_TRUE(windows->GetDictionary(i, &result_window));
|
| + result_ids.insert(GetWindowId(result_window));
|
| +
|
| + // "populate" was not passed in so tabs are not populated.
|
| + base::ListValue* tabs = nullptr;
|
| + EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs));
|
| + }
|
| + // The returned ids should contain all the current app, browser and
|
| + // devtools instance ids.
|
| + EXPECT_EQ(window_ids, result_ids);
|
| +
|
| + result_ids.clear();
|
| + function = new WindowsGetAllFunction();
|
| + function->set_extension(extension.get());
|
| + result.reset(utils::ToList(utils::RunFunctionAndReturnSingleResult(
|
| + function.get(),
|
| + "[{\"populate\": true, \"windowTypes\": [\"app\", \"devtools\", "
|
| + "\"normal\", \"panel\", \"popup\"]}]",
|
| + browser())));
|
| +
|
| + windows = result.get();
|
| + EXPECT_EQ(window_ids.size(), windows->GetSize());
|
| + for (size_t i = 0; i < windows->GetSize(); ++i) {
|
| + base::DictionaryValue* result_window = nullptr;
|
| + EXPECT_TRUE(windows->GetDictionary(i, &result_window));
|
| + result_ids.insert(GetWindowId(result_window));
|
| +
|
| + // "populate" was enabled so tabs should be populated.
|
| + base::ListValue* tabs = nullptr;
|
| + EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs));
|
| + }
|
| + // The returned ids should contain all the current app, browser and
|
| + // devtools instance ids.
|
| + EXPECT_EQ(window_ids, result_ids);
|
| +
|
| + DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
|
| +
|
| + CloseAppWindow(app_window);
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) {
|
| @@ -614,6 +700,354 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) {
|
| keys::kInvalidWindowStateError));
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateAppWindowSizeConstraint) {
|
| + AppWindow* app_window = CreateTestAppWindow(
|
| + "{\"outerBounds\": "
|
| + "{\"width\": 300, \"height\": 300,"
|
| + " \"minWidth\": 200, \"minHeight\": 200,"
|
| + " \"maxWidth\": 400, \"maxHeight\": 400}}");
|
| +
|
| + scoped_refptr<WindowsGetFunction> get_function = new WindowsGetFunction();
|
| + scoped_refptr<Extension> extension(test_util::CreateEmptyExtension().get());
|
| + get_function->set_extension(extension.get());
|
| + scoped_ptr<base::DictionaryValue> result(
|
| + utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
|
| + get_function.get(),
|
| + base::StringPrintf("[%u, {\"windowTypes\": [\"app\"]}]",
|
| + app_window->session_id().id()),
|
| + browser())));
|
| +
|
| + EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "width"));
|
| + EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "height"));
|
| +
|
| + // Verify the min width/height of the application window are
|
| + // respected.
|
| + scoped_refptr<WindowsUpdateFunction> update_min_function =
|
| + new WindowsUpdateFunction();
|
| + result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
|
| + update_min_function.get(),
|
| + base::StringPrintf("[%u, {\"width\": 100, \"height\": 100}]",
|
| + app_window->session_id().id()),
|
| + browser())));
|
| +
|
| + EXPECT_EQ(200, api_test_utils::GetInteger(result.get(), "width"));
|
| + EXPECT_EQ(200, api_test_utils::GetInteger(result.get(), "height"));
|
| +
|
| + // Verify the max width/height of the application window are
|
| + // respected.
|
| + scoped_refptr<WindowsUpdateFunction> update_max_function =
|
| + new WindowsUpdateFunction();
|
| + result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
|
| + update_max_function.get(),
|
| + base::StringPrintf("[%u, {\"width\": 500, \"height\": 500}]",
|
| + app_window->session_id().id()),
|
| + browser())));
|
| +
|
| + EXPECT_EQ(400, api_test_utils::GetInteger(result.get(), "width"));
|
| + EXPECT_EQ(400, api_test_utils::GetInteger(result.get(), "height"));
|
| +
|
| + CloseAppWindow(app_window);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateDevToolsWindow) {
|
| + DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| + browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
|
| +
|
| + scoped_refptr<WindowsGetFunction> get_function = new WindowsGetFunction();
|
| + scoped_refptr<Extension> extension(test_util::CreateEmptyExtension().get());
|
| + get_function->set_extension(extension.get());
|
| + scoped_ptr<base::DictionaryValue> result(
|
| + utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
|
| + get_function.get(),
|
| + base::StringPrintf(
|
| + "[%u, {\"windowTypes\": [\"devtools\"]}]",
|
| + ExtensionTabUtil::GetWindowId(
|
| + DevToolsWindowTesting::Get(devtools)->browser())),
|
| + browser())));
|
| +
|
| + // Verify the updating width/height works.
|
| + int32_t new_width = api_test_utils::GetInteger(result.get(), "width") - 50;
|
| + int32_t new_height = api_test_utils::GetInteger(result.get(), "height") - 50;
|
| +
|
| + scoped_refptr<WindowsUpdateFunction> update_function =
|
| + new WindowsUpdateFunction();
|
| + result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
|
| + update_function.get(),
|
| + base::StringPrintf("[%u, {\"width\": %d, \"height\": %d}]",
|
| + ExtensionTabUtil::GetWindowId(
|
| + DevToolsWindowTesting::Get(devtools)->browser()),
|
| + new_width, new_height),
|
| + browser())));
|
| +
|
| + EXPECT_EQ(new_width, api_test_utils::GetInteger(result.get(), "width"));
|
| + EXPECT_EQ(new_height, api_test_utils::GetInteger(result.get(), "height"));
|
| +
|
| + DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
|
| +}
|
| +
|
| +// TODO(llandwerlin): Activating a browser window and waiting for the
|
| +// action to happen requires views::Widget which is not available on
|
| +// MacOSX. Deactivate for now.
|
| +#if !defined(OS_MACOSX)
|
| +class ExtensionWindowLastFocusedTest : public ExtensionTabsTest {
|
| + public:
|
| + void SetUpOnMainThread() override;
|
| +
|
| + void ActivateAppWindow(AppWindow* app_window);
|
| +
|
| + void ActivateBrowserWindow(Browser* browser);
|
| +
|
| + Browser* CreateBrowserWithEmptyTab(bool as_popup);
|
| +
|
| + int GetTabId(const base::DictionaryValue* value) const;
|
| +
|
| + base::Value* RunFunction(UIThreadExtensionFunction* function,
|
| + const std::string& params);
|
| +
|
| + private:
|
| + // A helper class to wait for an AppWindow to become activated. On
|
| + // window system like X11, for a NativeWidget to be activated, we
|
| + // need to wait for the round trip communication with the X server.
|
| + class AppWindowActivatedWaiter : public AppWindowRegistry::Observer {
|
| + public:
|
| + AppWindowActivatedWaiter(AppWindow* app_window,
|
| + content::BrowserContext* browser_context)
|
| + : app_window_(app_window),
|
| + browser_context_(browser_context),
|
| + waiting_(false) {
|
| + AppWindowRegistry::Get(browser_context_)->AddObserver(this);
|
| + }
|
| + ~AppWindowActivatedWaiter() override {
|
| + AppWindowRegistry::Get(browser_context_)->RemoveObserver(this);
|
| + }
|
| +
|
| + void ActivateAndWait() {
|
| + app_window_->GetBaseWindow()->Activate();
|
| + if (!app_window_->GetBaseWindow()->IsActive()) {
|
| + waiting_ = true;
|
| + content::RunMessageLoop();
|
| + }
|
| + }
|
| +
|
| + // AppWindowRegistry::Observer:
|
| + void OnAppWindowActivated(AppWindow* app_window) override {
|
| + if (app_window_ == app_window && waiting_) {
|
| + base::MessageLoopForUI::current()->Quit();
|
| + waiting_ = false;
|
| + }
|
| + }
|
| +
|
| + private:
|
| + AppWindow* app_window_;
|
| + content::BrowserContext* browser_context_;
|
| + bool waiting_;
|
| + };
|
| +
|
| + // A helper class to wait for an views::Widget to become activated.
|
| + class WidgetActivatedWaiter : public views::WidgetObserver {
|
| + public:
|
| + explicit WidgetActivatedWaiter(views::Widget* widget)
|
| + : widget_(widget), waiting_(false) {
|
| + widget_->AddObserver(this);
|
| + }
|
| + ~WidgetActivatedWaiter() override { widget_->RemoveObserver(this); }
|
| +
|
| + void ActivateAndWait() {
|
| + widget_->Activate();
|
| + if (!widget_->IsActive()) {
|
| + waiting_ = true;
|
| + content::RunMessageLoop();
|
| + }
|
| + }
|
| +
|
| + // views::WidgetObserver:
|
| + void OnWidgetActivationChanged(views::Widget* widget,
|
| + bool active) override {
|
| + if (widget_ == widget && waiting_) {
|
| + base::MessageLoopForUI::current()->Quit();
|
| + waiting_ = false;
|
| + }
|
| + }
|
| +
|
| + private:
|
| + views::Widget* widget_;
|
| + bool waiting_;
|
| + };
|
| +
|
| + scoped_refptr<Extension> extension_;
|
| +};
|
| +
|
| +void ExtensionWindowLastFocusedTest::SetUpOnMainThread() {
|
| + ExtensionTabsTest::SetUpOnMainThread();
|
| + extension_ = test_util::CreateEmptyExtension();
|
| +}
|
| +
|
| +void ExtensionWindowLastFocusedTest::ActivateAppWindow(AppWindow* app_window) {
|
| + AppWindowActivatedWaiter waiter(app_window, browser()->profile());
|
| + waiter.ActivateAndWait();
|
| +}
|
| +
|
| +void ExtensionWindowLastFocusedTest::ActivateBrowserWindow(Browser* browser) {
|
| + BrowserView* view = BrowserView::GetBrowserViewForBrowser(browser);
|
| + EXPECT_NE(nullptr, view);
|
| + views::Widget* widget = view->frame();
|
| + EXPECT_NE(nullptr, widget);
|
| + WidgetActivatedWaiter waiter(widget);
|
| + waiter.ActivateAndWait();
|
| +}
|
| +
|
| +Browser* ExtensionWindowLastFocusedTest::CreateBrowserWithEmptyTab(
|
| + bool as_popup) {
|
| + Browser* new_browser;
|
| + if (as_popup)
|
| + new_browser = new Browser(
|
| + Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(),
|
| + browser()->host_desktop_type()));
|
| + else
|
| + new_browser = new Browser(Browser::CreateParams(
|
| + browser()->profile(), browser()->host_desktop_type()));
|
| + AddBlankTabAndShow(new_browser);
|
| + return new_browser;
|
| +}
|
| +
|
| +int ExtensionWindowLastFocusedTest::GetTabId(
|
| + const base::DictionaryValue* value) const {
|
| + const base::ListValue* tabs = NULL;
|
| + if (!value->GetList(keys::kTabsKey, &tabs))
|
| + return -2;
|
| + const base::Value* tab = NULL;
|
| + if (!tabs->Get(0, &tab))
|
| + return -2;
|
| + const base::DictionaryValue* tab_dict = NULL;
|
| + if (!tab->GetAsDictionary(&tab_dict))
|
| + return -2;
|
| + int tab_id = 0;
|
| + if (!tab_dict->GetInteger(keys::kIdKey, &tab_id))
|
| + return -2;
|
| + return tab_id;
|
| +}
|
| +
|
| +base::Value* ExtensionWindowLastFocusedTest::RunFunction(
|
| + UIThreadExtensionFunction* function,
|
| + const std::string& params) {
|
| + function->set_extension(extension_.get());
|
| + return utils::RunFunctionAndReturnSingleResult(function, params, browser());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionWindowLastFocusedTest,
|
| + NoDevtoolsAndAppWindows) {
|
| + DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| + browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
|
| + {
|
| + int devtools_window_id = ExtensionTabUtil::GetWindowId(
|
| + DevToolsWindowTesting::Get(devtools)->browser());
|
| + ActivateBrowserWindow(DevToolsWindowTesting::Get(devtools)->browser());
|
| +
|
| + scoped_refptr<WindowsGetLastFocusedFunction> function =
|
| + new WindowsGetLastFocusedFunction();
|
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
|
| + RunFunction(function.get(), "[{\"populate\": true}]")));
|
| + EXPECT_NE(devtools_window_id,
|
| + api_test_utils::GetInteger(result.get(), "id"));
|
| + }
|
| +
|
| + AppWindow* app_window = CreateTestAppWindow(
|
| + "{\"outerBounds\": "
|
| + "{\"width\": 300, \"height\": 300,"
|
| + " \"minWidth\": 200, \"minHeight\": 200,"
|
| + " \"maxWidth\": 400, \"maxHeight\": 400}}");
|
| + {
|
| + ActivateAppWindow(app_window);
|
| +
|
| + scoped_refptr<WindowsGetLastFocusedFunction> get_current_app_function =
|
| + new WindowsGetLastFocusedFunction();
|
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
|
| + RunFunction(get_current_app_function.get(), "[{\"populate\": true}]")));
|
| + int app_window_id = app_window->session_id().id();
|
| + EXPECT_NE(app_window_id, api_test_utils::GetInteger(result.get(), "id"));
|
| + }
|
| +
|
| + DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
|
| + CloseAppWindow(app_window);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionWindowLastFocusedTest,
|
| + NoTabIdForDevToolsAndAppWindows) {
|
| + Browser* normal_browser = CreateBrowserWithEmptyTab(false);
|
| + {
|
| + ActivateBrowserWindow(normal_browser);
|
| +
|
| + scoped_refptr<WindowsGetLastFocusedFunction> function =
|
| + new WindowsGetLastFocusedFunction();
|
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
|
| + RunFunction(function.get(), "[{\"populate\": true}]")));
|
| + int normal_browser_window_id =
|
| + ExtensionTabUtil::GetWindowId(normal_browser);
|
| + EXPECT_EQ(normal_browser_window_id,
|
| + api_test_utils::GetInteger(result.get(), "id"));
|
| + EXPECT_NE(-1, GetTabId(result.get()));
|
| + EXPECT_EQ("normal", api_test_utils::GetString(result.get(), "type"));
|
| + }
|
| +
|
| + Browser* popup_browser = CreateBrowserWithEmptyTab(true);
|
| + {
|
| + ActivateBrowserWindow(popup_browser);
|
| +
|
| + scoped_refptr<WindowsGetLastFocusedFunction> function =
|
| + new WindowsGetLastFocusedFunction();
|
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
|
| + RunFunction(function.get(), "[{\"populate\": true}]")));
|
| + int popup_browser_window_id = ExtensionTabUtil::GetWindowId(popup_browser);
|
| + EXPECT_EQ(popup_browser_window_id,
|
| + api_test_utils::GetInteger(result.get(), "id"));
|
| + EXPECT_NE(-1, GetTabId(result.get()));
|
| + EXPECT_EQ("popup", api_test_utils::GetString(result.get(), "type"));
|
| + }
|
| +
|
| + DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| + browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
|
| + {
|
| + ActivateBrowserWindow(DevToolsWindowTesting::Get(devtools)->browser());
|
| +
|
| + scoped_refptr<WindowsGetLastFocusedFunction> function =
|
| + new WindowsGetLastFocusedFunction();
|
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(RunFunction(
|
| + function.get(),
|
| + "[{\"populate\": true, \"windowTypes\": [ \"devtools\" ]}]")));
|
| + int devtools_window_id = ExtensionTabUtil::GetWindowId(
|
| + DevToolsWindowTesting::Get(devtools)->browser());
|
| + EXPECT_EQ(devtools_window_id,
|
| + api_test_utils::GetInteger(result.get(), "id"));
|
| + EXPECT_EQ(-1, GetTabId(result.get()));
|
| + EXPECT_EQ("devtools", api_test_utils::GetString(result.get(), "type"));
|
| + }
|
| +
|
| + AppWindow* app_window = CreateTestAppWindow(
|
| + "{\"outerBounds\": "
|
| + "{\"width\": 300, \"height\": 300,"
|
| + " \"minWidth\": 200, \"minHeight\": 200,"
|
| + " \"maxWidth\": 400, \"maxHeight\": 400}}");
|
| + {
|
| + ActivateAppWindow(app_window);
|
| +
|
| + scoped_refptr<WindowsGetLastFocusedFunction> get_current_app_function =
|
| + new WindowsGetLastFocusedFunction();
|
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
|
| + RunFunction(get_current_app_function.get(),
|
| + "[{\"populate\": true, \"windowTypes\": [ \"app\" ]}]")));
|
| + int app_window_id = app_window->session_id().id();
|
| + EXPECT_EQ(app_window_id, api_test_utils::GetInteger(result.get(), "id"));
|
| + EXPECT_EQ(-1, GetTabId(result.get()));
|
| + EXPECT_EQ("app", api_test_utils::GetString(result.get(), "type"));
|
| + }
|
| +
|
| + chrome::CloseWindow(normal_browser);
|
| + chrome::CloseWindow(popup_browser);
|
| + DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
|
| + CloseAppWindow(app_window);
|
| +}
|
| +#endif // !defined(OS_MACOSX)
|
| +
|
| IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) {
|
| scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
|
| scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
|
| @@ -773,7 +1207,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTabNoPermission) {
|
| IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, NoTabsEventOnDevTools) {
|
| extensions::ResultCatcher catcher;
|
| ExtensionTestMessageListener listener("ready", true);
|
| - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("tabs/no_events")));
|
| + ASSERT_TRUE(
|
| + LoadExtension(test_data_dir_.AppendASCII("api_test/tabs/no_events")));
|
| ASSERT_TRUE(listener.WaitUntilSatisfied());
|
|
|
| DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| @@ -786,6 +1221,57 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, NoTabsEventOnDevTools) {
|
| DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, NoTabsAppWindow) {
|
| + extensions::ResultCatcher catcher;
|
| + ExtensionTestMessageListener listener("ready", true);
|
| + ASSERT_TRUE(
|
| + LoadExtension(test_data_dir_.AppendASCII("api_test/tabs/no_events")));
|
| + ASSERT_TRUE(listener.WaitUntilSatisfied());
|
| +
|
| + AppWindow* app_window = CreateTestAppWindow(
|
| + "{\"outerBounds\": "
|
| + "{\"width\": 300, \"height\": 300,"
|
| + " \"minWidth\": 200, \"minHeight\": 200,"
|
| + " \"maxWidth\": 400, \"maxHeight\": 400}}");
|
| +
|
| + listener.Reply("stop");
|
| +
|
| + ASSERT_TRUE(catcher.GetNextResult());
|
| +
|
| + CloseAppWindow(app_window);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, FilteredEvents) {
|
| + extensions::ResultCatcher catcher;
|
| + ExtensionTestMessageListener listener("ready", true);
|
| + ASSERT_TRUE(
|
| + LoadExtension(test_data_dir_.AppendASCII("api_test/windows/events")));
|
| + ASSERT_TRUE(listener.WaitUntilSatisfied());
|
| +
|
| + AppWindow* app_window = CreateTestAppWindow(
|
| + "{\"outerBounds\": "
|
| + "{\"width\": 300, \"height\": 300,"
|
| + " \"minWidth\": 200, \"minHeight\": 200,"
|
| + " \"maxWidth\": 400, \"maxHeight\": 400}}");
|
| +
|
| + Browser* browser_window = new Browser(Browser::CreateParams(
|
| + browser()->profile(), browser()->host_desktop_type()));
|
| + AddBlankTabAndShow(browser_window);
|
| +
|
| + DevToolsWindow* devtools_window =
|
| + DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| + browser()->tab_strip_model()->GetWebContentsAt(0),
|
| + false /* is_docked */);
|
| +
|
| + chrome::CloseWindow(browser_window);
|
| + DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
|
| + CloseAppWindow(app_window);
|
| +
|
| + listener.Reply("stop");
|
| +
|
| + ASSERT_TRUE(catcher.GetNextResult());
|
| +}
|
| +
|
| IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, ExecuteScriptOnDevTools) {
|
| scoped_ptr<base::DictionaryValue> test_extension_value(
|
| api_test_utils::ParseDictionary(
|
|
|