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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/devtools/devtools_window_testing.h" |
14 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 15 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
16 #include "chrome/browser/extensions/extension_function_test_utils.h" | 17 #include "chrome/browser/extensions/extension_function_test_utils.h" |
17 #include "chrome/browser/extensions/extension_tab_util.h" | 18 #include "chrome/browser/extensions/extension_tab_util.h" |
18 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 19 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
22 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 const size_t NUM_WINDOWS = 5; | 182 const size_t NUM_WINDOWS = 5; |
182 std::set<int> window_ids; | 183 std::set<int> window_ids; |
183 std::set<int> result_ids; | 184 std::set<int> result_ids; |
184 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); | 185 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); |
185 | 186 |
186 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { | 187 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { |
187 Browser* new_browser = CreateBrowser(browser()->profile()); | 188 Browser* new_browser = CreateBrowser(browser()->profile()); |
188 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); | 189 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); |
189 } | 190 } |
190 | 191 |
| 192 // Undocked DevTools window should not be accessible. |
| 193 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| 194 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); |
| 195 |
191 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); | 196 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); |
192 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 197 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
193 function->set_extension(extension.get()); | 198 function->set_extension(extension.get()); |
194 scoped_ptr<base::ListValue> result(utils::ToList( | 199 scoped_ptr<base::ListValue> result(utils::ToList( |
195 utils::RunFunctionAndReturnSingleResult(function.get(), | 200 utils::RunFunctionAndReturnSingleResult(function.get(), |
196 "[]", | 201 "[]", |
197 browser()))); | 202 browser()))); |
198 | 203 |
199 base::ListValue* windows = result.get(); | 204 base::ListValue* windows = result.get(); |
200 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); | 205 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); |
(...skipping 23 matching lines...) Expand all Loading... |
224 base::DictionaryValue* result_window = NULL; | 229 base::DictionaryValue* result_window = NULL; |
225 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); | 230 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); |
226 result_ids.insert(utils::GetInteger(result_window, "id")); | 231 result_ids.insert(utils::GetInteger(result_window, "id")); |
227 | 232 |
228 // "populate" was enabled so tabs should be populated. | 233 // "populate" was enabled so tabs should be populated. |
229 base::ListValue* tabs = NULL; | 234 base::ListValue* tabs = NULL; |
230 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); | 235 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); |
231 } | 236 } |
232 // The returned ids should contain all the current browser instance ids. | 237 // The returned ids should contain all the current browser instance ids. |
233 EXPECT_EQ(window_ids, result_ids); | 238 EXPECT_EQ(window_ids, result_ids); |
| 239 |
| 240 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); |
234 } | 241 } |
235 | 242 |
236 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { | 243 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { |
237 // The test empty extension has no permissions, therefore it should not get | 244 // The test empty extension has no permissions, therefore it should not get |
238 // tab data in the function result. | 245 // tab data in the function result. |
239 scoped_refptr<TabsUpdateFunction> update_tab_function( | 246 scoped_refptr<TabsUpdateFunction> update_tab_function( |
240 new TabsUpdateFunction()); | 247 new TabsUpdateFunction()); |
241 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 248 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
242 update_tab_function->set_extension(empty_extension.get()); | 249 update_tab_function->set_extension(empty_extension.get()); |
243 // Without a callback the function will not generate a result. | 250 // Without a callback the function will not generate a result. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 result_tabs = result.get(); | 437 result_tabs = result.get(); |
431 // We should have one tab for each extra window. | 438 // We should have one tab for each extra window. |
432 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); | 439 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); |
433 for (size_t i = 0; i < kExtraWindows; ++i) { | 440 for (size_t i = 0; i < kExtraWindows; ++i) { |
434 base::DictionaryValue* result_tab = NULL; | 441 base::DictionaryValue* result_tab = NULL; |
435 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 442 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
436 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); | 443 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); |
437 } | 444 } |
438 } | 445 } |
439 | 446 |
| 447 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryAllTabsWithDevTools) { |
| 448 const size_t kNumWindows = 3; |
| 449 std::set<int> window_ids; |
| 450 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); |
| 451 for (size_t i = 0; i < kNumWindows - 1; ++i) { |
| 452 Browser* new_browser = CreateBrowser(browser()->profile()); |
| 453 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); |
| 454 } |
| 455 |
| 456 // Undocked DevTools window should not be accessible. |
| 457 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| 458 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); |
| 459 |
| 460 // Get tabs in the 'current' window called from non-focused browser. |
| 461 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); |
| 462 function->set_extension(test_util::CreateEmptyExtension().get()); |
| 463 scoped_ptr<base::ListValue> result(utils::ToList( |
| 464 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 465 "[{}]", |
| 466 browser()))); |
| 467 |
| 468 std::set<int> result_ids; |
| 469 base::ListValue* result_tabs = result.get(); |
| 470 // We should have one tab per browser except for DevTools. |
| 471 EXPECT_EQ(kNumWindows, result_tabs->GetSize()); |
| 472 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
| 473 base::DictionaryValue* result_tab = NULL; |
| 474 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
| 475 result_ids.insert(utils::GetInteger(result_tab, keys::kWindowIdKey)); |
| 476 } |
| 477 EXPECT_EQ(window_ids, result_ids); |
| 478 |
| 479 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); |
| 480 } |
| 481 |
440 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { | 482 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { |
441 // Test creates new popup window, closes it right away and then tries to open | 483 // Test creates new popup window, closes it right away and then tries to open |
442 // a new tab in it. Tab should not be opened in the popup window, but in a | 484 // a new tab in it. Tab should not be opened in the popup window, but in a |
443 // tabbed browser window. | 485 // tabbed browser window. |
444 Browser* popup_browser = new Browser( | 486 Browser* popup_browser = new Browser( |
445 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(), | 487 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(), |
446 browser()->host_desktop_type())); | 488 browser()->host_desktop_type())); |
447 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); | 489 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); |
448 chrome::CloseWindow(popup_browser); | 490 chrome::CloseWindow(popup_browser); |
449 | 491 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 // Test chrome.tabs.setZoom(). | 957 // Test chrome.tabs.setZoom(). |
916 error = RunSetZoomExpectError(tab_id, 3.14159); | 958 error = RunSetZoomExpectError(tab_id, 3.14159); |
917 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 959 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
918 | 960 |
919 // chrome.tabs.setZoomSettings(). | 961 // chrome.tabs.setZoomSettings(). |
920 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 962 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
921 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 963 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
922 } | 964 } |
923 | 965 |
924 } // namespace extensions | 966 } // namespace extensions |
OLD | NEW |