OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/json/json_writer.h" | |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/apps/app_browsertest_util.h" | |
14 #include "chrome/browser/devtools/devtools_window_testing.h" | 17 #include "chrome/browser/devtools/devtools_window_testing.h" |
15 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 18 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 19 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
17 #include "chrome/browser/extensions/extension_function_test_utils.h" | 20 #include "chrome/browser/extensions/extension_function_test_utils.h" |
18 #include "chrome/browser/extensions/extension_tab_util.h" | 21 #include "chrome/browser/extensions/extension_tab_util.h" |
19 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 22 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
20 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
23 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
34 #include "extensions/common/test_util.h" | 37 #include "extensions/common/test_util.h" |
35 #include "net/test/spawned_test_server/spawned_test_server.h" | 38 #include "net/test/spawned_test_server/spawned_test_server.h" |
36 #include "ui/gfx/geometry/rect.h" | 39 #include "ui/gfx/geometry/rect.h" |
37 | 40 |
38 namespace extensions { | 41 namespace extensions { |
39 | 42 |
40 namespace keys = tabs_constants; | 43 namespace keys = tabs_constants; |
41 namespace utils = extension_function_test_utils; | 44 namespace utils = extension_function_test_utils; |
42 | 45 |
43 namespace { | 46 namespace { |
44 using ExtensionTabsTest = InProcessBrowserTest; | 47 using ExtensionTabsTest = PlatformAppBrowserTest; |
45 | 48 |
46 class ExtensionWindowCreateTest : public InProcessBrowserTest { | 49 class ExtensionWindowCreateTest : public InProcessBrowserTest { |
47 public: | 50 public: |
48 // Runs chrome.windows.create(), expecting an error. | 51 // Runs chrome.windows.create(), expecting an error. |
49 std::string RunCreateWindowExpectError(const std::string& args) { | 52 std::string RunCreateWindowExpectError(const std::string& args) { |
50 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction); | 53 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction); |
51 function->set_extension(test_util::CreateEmptyExtension().get()); | 54 function->set_extension(test_util::CreateEmptyExtension().get()); |
52 return api_test_utils::RunFunctionAndReturnError(function.get(), args, | 55 return api_test_utils::RunFunctionAndReturnError(function.get(), args, |
53 browser()->profile()); | 56 browser()->profile()); |
54 } | 57 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 const size_t NUM_WINDOWS = 5; | 199 const size_t NUM_WINDOWS = 5; |
197 std::set<int> window_ids; | 200 std::set<int> window_ids; |
198 std::set<int> result_ids; | 201 std::set<int> result_ids; |
199 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); | 202 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); |
200 | 203 |
201 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { | 204 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { |
202 Browser* new_browser = CreateBrowser(browser()->profile()); | 205 Browser* new_browser = CreateBrowser(browser()->profile()); |
203 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); | 206 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); |
204 } | 207 } |
205 | 208 |
209 // Application windows should not be accessible without the | |
210 // windows.global permission. | |
211 AppWindow* app_window = CreateTestAppWindow("{}"); | |
212 | |
206 // Undocked DevTools window should not be accessible. | 213 // Undocked DevTools window should not be accessible. |
207 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( | 214 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( |
208 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); | 215 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); |
209 | 216 |
210 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); | 217 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); |
211 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 218 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
212 function->set_extension(extension.get()); | 219 function->set_extension(extension.get()); |
213 scoped_ptr<base::ListValue> result(utils::ToList( | 220 scoped_ptr<base::ListValue> result(utils::ToList( |
214 utils::RunFunctionAndReturnSingleResult(function.get(), | 221 utils::RunFunctionAndReturnSingleResult(function.get(), |
215 "[]", | 222 "[]", |
(...skipping 29 matching lines...) Expand all Loading... | |
245 result_ids.insert(api_test_utils::GetInteger(result_window, "id")); | 252 result_ids.insert(api_test_utils::GetInteger(result_window, "id")); |
246 | 253 |
247 // "populate" was enabled so tabs should be populated. | 254 // "populate" was enabled so tabs should be populated. |
248 base::ListValue* tabs = NULL; | 255 base::ListValue* tabs = NULL; |
249 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); | 256 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); |
250 } | 257 } |
251 // The returned ids should contain all the current browser instance ids. | 258 // The returned ids should contain all the current browser instance ids. |
252 EXPECT_EQ(window_ids, result_ids); | 259 EXPECT_EQ(window_ids, result_ids); |
253 | 260 |
254 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | 261 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); |
262 | |
263 CloseAppWindow(app_window); | |
264 } | |
265 | |
266 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindowsGlobal) { | |
267 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.
| |
268 std::set<int> window_ids; | |
269 std::set<int> result_ids; | |
270 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); | |
271 | |
272 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { | |
273 Browser* new_browser = CreateBrowser(browser()->profile()); | |
274 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); | |
275 } | |
276 | |
277 // Application windows should be visible with the windows.global | |
278 // permission. | |
279 AppWindow* app_window = CreateTestAppWindow("{}"); | |
280 window_ids.insert(app_window->session_id().id()); | |
281 | |
282 // Undocked DevTools window should not be accessible. | |
283 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( | |
284 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); | |
285 | |
286 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); | |
287 scoped_ptr<base::DictionaryValue> global_extension_value( | |
288 api_test_utils::ParseDictionary( | |
289 "{\"name\": \"Global\", \"version\": \"1.0\", \"permissions\": " | |
290 "[\"windows.global\"]}")); | |
291 scoped_refptr<Extension> extension( | |
292 api_test_utils::CreateExtension(global_extension_value.get())); | |
293 function->set_extension(extension.get()); | |
294 scoped_ptr<base::ListValue> result( | |
295 utils::ToList(utils::RunFunctionAndReturnSingleResult(function.get(), | |
296 "[]", browser()))); | |
297 | |
298 base::ListValue* windows = result.get(); | |
299 EXPECT_EQ(NUM_WINDOWS + 1, windows->GetSize()); | |
300 for (size_t i = 0; i < result->GetSize(); ++i) { | |
301 base::DictionaryValue* result_window = NULL; | |
302 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); | |
303 result_ids.insert(api_test_utils::GetInteger(result_window, "id")); | |
304 | |
305 // "populate" was not passed in so tabs are not populated. | |
306 base::ListValue* tabs = NULL; | |
307 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs)); | |
308 } | |
309 // The returned ids should contain all the current browser instance ids. | |
310 EXPECT_EQ(window_ids, result_ids); | |
311 | |
312 result_ids.clear(); | |
313 function = new WindowsGetAllFunction(); | |
314 function->set_extension(extension.get()); | |
315 result.reset(utils::ToList(utils::RunFunctionAndReturnSingleResult( | |
316 function.get(), "[{\"populate\": true}]", browser()))); | |
317 | |
318 windows = result.get(); | |
319 EXPECT_EQ(NUM_WINDOWS + 1, windows->GetSize()); | |
320 for (size_t i = 0; i < windows->GetSize(); ++i) { | |
321 base::DictionaryValue* result_window = NULL; | |
322 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); | |
323 result_ids.insert(api_test_utils::GetInteger(result_window, "id")); | |
324 | |
325 // "populate" was enabled so tabs should be populated. | |
326 base::ListValue* tabs = NULL; | |
327 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); | |
328 } | |
329 // The returned ids should contain all the current browser instance ids. | |
330 EXPECT_EQ(window_ids, result_ids); | |
331 | |
332 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
333 | |
334 CloseAppWindow(app_window); | |
255 } | 335 } |
256 | 336 |
257 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { | 337 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { |
258 // The test empty extension has no permissions, therefore it should not get | 338 // The test empty extension has no permissions, therefore it should not get |
259 // tab data in the function result. | 339 // tab data in the function result. |
260 scoped_refptr<TabsUpdateFunction> update_tab_function( | 340 scoped_refptr<TabsUpdateFunction> update_tab_function( |
261 new TabsUpdateFunction()); | 341 new TabsUpdateFunction()); |
262 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 342 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
263 update_tab_function->set_extension(empty_extension.get()); | 343 update_tab_function->set_extension(empty_extension.get()); |
264 // Without a callback the function will not generate a result. | 344 // Without a callback the function will not generate a result. |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 function = new WindowsUpdateFunction(); | 646 function = new WindowsUpdateFunction(); |
567 function->set_extension(extension.get()); | 647 function->set_extension(extension.get()); |
568 EXPECT_TRUE(MatchPattern( | 648 EXPECT_TRUE(MatchPattern( |
569 utils::RunFunctionAndReturnError( | 649 utils::RunFunctionAndReturnError( |
570 function.get(), | 650 function.get(), |
571 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 651 base::StringPrintf(kArgsMaximizedWithBounds, window_id), |
572 browser()), | 652 browser()), |
573 keys::kInvalidWindowStateError)); | 653 keys::kInvalidWindowStateError)); |
574 } | 654 } |
575 | 655 |
656 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateAppWindowSizeConstraint) { | |
657 AppWindow* app_window = CreateTestAppWindow( | |
658 "{\"outerBounds\": " | |
659 "{\"width\": 300, \"height\": 300," | |
660 " \"minWidth\": 200, \"minHeight\": 200," | |
661 " \"maxWidth\": 400, \"maxHeight\": 400}}"); | |
662 | |
663 scoped_refptr<WindowsGetFunction> get_function = new WindowsGetFunction(); | |
664 scoped_ptr<base::DictionaryValue> extension_value( | |
665 api_test_utils::ParseDictionary( | |
666 "{\"name\": \"Global\", \"version\": \"1.0\", \"permissions\": " | |
667 "[\"windows.global\"]}")); | |
668 scoped_refptr<Extension> extension( | |
669 api_test_utils::CreateExtension(extension_value.get())); | |
670 get_function->set_extension(extension.get()); | |
671 scoped_ptr<base::DictionaryValue> result( | |
672 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | |
673 get_function.get(), | |
674 base::StringPrintf("[%u]", app_window->session_id().id()), | |
675 browser()))); | |
676 | |
677 EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "width")); | |
678 EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "height")); | |
679 | |
680 // Verify the min width/height of the application window are | |
681 // respected. | |
682 scoped_refptr<WindowsUpdateFunction> update_min_function = | |
683 new WindowsUpdateFunction(); | |
684 result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | |
685 update_min_function.get(), | |
686 base::StringPrintf("[%u, {\"width\": 100, \"height\": 100}]", | |
687 app_window->session_id().id()), | |
688 browser()))); | |
689 | |
690 EXPECT_EQ(200, api_test_utils::GetInteger(result.get(), "width")); | |
691 EXPECT_EQ(200, api_test_utils::GetInteger(result.get(), "height")); | |
692 | |
693 // Verify the max width/height of the application window are | |
694 // respected. | |
695 scoped_refptr<WindowsUpdateFunction> update_max_function = | |
696 new WindowsUpdateFunction(); | |
697 result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | |
698 update_max_function.get(), | |
699 base::StringPrintf("[%u, {\"width\": 500, \"height\": 500}]", | |
700 app_window->session_id().id()), | |
701 browser()))); | |
702 | |
703 EXPECT_EQ(400, api_test_utils::GetInteger(result.get(), "width")); | |
704 EXPECT_EQ(400, api_test_utils::GetInteger(result.get(), "height")); | |
705 | |
706 CloseAppWindow(app_window); | |
707 } | |
708 | |
576 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { | 709 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { |
577 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); | 710 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); |
578 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 711 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
579 function->set_extension(extension.get()); | 712 function->set_extension(extension.get()); |
580 | 713 |
581 scoped_ptr<base::DictionaryValue> result( | 714 scoped_ptr<base::DictionaryValue> result( |
582 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | 715 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( |
583 function.get(), "[{\"state\": \"minimized\"}]", browser(), | 716 function.get(), "[{\"state\": \"minimized\"}]", browser(), |
584 utils::INCLUDE_INCOGNITO))); | 717 utils::INCLUDE_INCOGNITO))); |
585 int window_id = api_test_utils::GetInteger(result.get(), "id"); | 718 int window_id = api_test_utils::GetInteger(result.get(), "id"); |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1165 // Test chrome.tabs.setZoom(). | 1298 // Test chrome.tabs.setZoom(). |
1166 error = RunSetZoomExpectError(tab_id, 3.14159); | 1299 error = RunSetZoomExpectError(tab_id, 3.14159); |
1167 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1300 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1168 | 1301 |
1169 // chrome.tabs.setZoomSettings(). | 1302 // chrome.tabs.setZoomSettings(). |
1170 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 1303 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
1171 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1304 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1172 } | 1305 } |
1173 | 1306 |
1174 } // namespace extensions | 1307 } // namespace extensions |
OLD | NEW |