Chromium Code Reviews| 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 e45f3074b1ca6694966b0d772b35e508b8a5aa69..c7410452d9c81f43dfbb54b921e7cc0d82fdcf63 100644 |
| --- a/chrome/browser/extensions/api/tabs/tabs_test.cc |
| +++ b/chrome/browser/extensions/api/tabs/tabs_test.cc |
| @@ -5,12 +5,15 @@ |
| #include <string> |
| +#include "base/json/json_writer.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/prefs/pref_service.h" |
| +#include "base/strings/string_number_conversions.h" |
| #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" |
| @@ -41,7 +44,7 @@ namespace keys = tabs_constants; |
| namespace utils = extension_function_test_utils; |
| namespace { |
| -using ExtensionTabsTest = InProcessBrowserTest; |
| +using ExtensionTabsTest = PlatformAppBrowserTest; |
| class ExtensionWindowCreateTest : public InProcessBrowserTest { |
| public: |
| @@ -203,6 +206,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) { |
| window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); |
| } |
| + // Application windows should not be accessible without the |
| + // windows.global permission. |
| + AppWindow* app_window = CreateTestAppWindow("{}"); |
| + |
| // Undocked DevTools window should not be accessible. |
| DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); |
| @@ -252,6 +259,79 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) { |
| EXPECT_EQ(window_ids, result_ids); |
| DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); |
| + |
| + CloseAppWindow(app_window); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindowsGlobal) { |
| + const size_t NUM_WINDOWS = 5; |
|
dcheng
2015/06/29 18:15:49
Nit: kNumWindows is the naming convention for cons
llandwerlin-old
2015/06/30 10:20:47
Done.
|
| + 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 visible with the windows.global |
| + // permission. |
| + AppWindow* app_window = CreateTestAppWindow("{}"); |
| + window_ids.insert(app_window->session_id().id()); |
| + |
| + // Undocked DevTools window should not be accessible. |
| + DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| + browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); |
| + |
| + scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); |
| + scoped_ptr<base::DictionaryValue> global_extension_value( |
| + api_test_utils::ParseDictionary( |
| + "{\"name\": \"Global\", \"version\": \"1.0\", \"permissions\": " |
| + "[\"windows.global\"]}")); |
| + scoped_refptr<Extension> extension( |
| + api_test_utils::CreateExtension(global_extension_value.get())); |
| + function->set_extension(extension.get()); |
| + scoped_ptr<base::ListValue> result( |
| + utils::ToList(utils::RunFunctionAndReturnSingleResult(function.get(), |
| + "[]", browser()))); |
| + |
| + base::ListValue* windows = result.get(); |
| + EXPECT_EQ(NUM_WINDOWS + 1, windows->GetSize()); |
| + for (size_t i = 0; i < result->GetSize(); ++i) { |
| + base::DictionaryValue* result_window = NULL; |
| + EXPECT_TRUE(windows->GetDictionary(i, &result_window)); |
| + result_ids.insert(api_test_utils::GetInteger(result_window, "id")); |
| + |
| + // "populate" was not passed in so tabs are not populated. |
| + base::ListValue* tabs = NULL; |
| + EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs)); |
| + } |
| + // The returned ids should contain all the current browser 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}]", browser()))); |
| + |
| + windows = result.get(); |
| + EXPECT_EQ(NUM_WINDOWS + 1, windows->GetSize()); |
| + for (size_t i = 0; i < windows->GetSize(); ++i) { |
| + base::DictionaryValue* result_window = NULL; |
| + EXPECT_TRUE(windows->GetDictionary(i, &result_window)); |
| + result_ids.insert(api_test_utils::GetInteger(result_window, "id")); |
| + |
| + // "populate" was enabled so tabs should be populated. |
| + base::ListValue* tabs = NULL; |
| + EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); |
| + } |
| + // The returned ids should contain all the current browser instance ids. |
| + EXPECT_EQ(window_ids, result_ids); |
| + |
| + DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); |
| + |
| + CloseAppWindow(app_window); |
| } |
| IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { |
| @@ -573,6 +653,59 @@ 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_ptr<base::DictionaryValue> extension_value( |
| + api_test_utils::ParseDictionary( |
| + "{\"name\": \"Global\", \"version\": \"1.0\", \"permissions\": " |
| + "[\"windows.global\"]}")); |
| + scoped_refptr<Extension> extension( |
| + api_test_utils::CreateExtension(extension_value.get())); |
| + get_function->set_extension(extension.get()); |
| + scoped_ptr<base::DictionaryValue> result( |
| + utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( |
| + get_function.get(), |
| + base::StringPrintf("[%u]", 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(ExtensionWindowCreateTest, AcceptState) { |
| scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); |
| scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |