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/extensions/api/tabs/tabs_api.h" | 14 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
16 #include "chrome/browser/extensions/extension_function_test_utils.h" | 16 #include "chrome/browser/extensions/extension_function_test_utils.h" |
17 #include "chrome/browser/extensions/extension_tab_util.h" | 17 #include "chrome/browser/extensions/extension_tab_util.h" |
18 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 18 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_commands.h" | 21 #include "chrome/browser/ui/browser_commands.h" |
22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
26 #include "content/public/common/page_zoom.h" | 26 #include "content/public/common/page_zoom.h" |
27 #include "content/public/common/url_constants.h" | 27 #include "content/public/common/url_constants.h" |
28 #include "extensions/common/manifest_constants.h" | 28 #include "extensions/common/manifest_constants.h" |
29 #include "extensions/common/test_util.h" | 29 #include "extensions/common/test_util.h" |
| 30 #include "net/test/spawned_test_server/spawned_test_server.h" |
30 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/rect.h" |
31 | 32 |
32 namespace extensions { | 33 namespace extensions { |
33 | 34 |
34 namespace keys = tabs_constants; | 35 namespace keys = tabs_constants; |
35 namespace utils = extension_function_test_utils; | 36 namespace utils = extension_function_test_utils; |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 class ExtensionTabsTest : public InProcessBrowserTest { | 40 class ExtensionTabsTest : public InProcessBrowserTest { |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 EXPECT_EQ(kZoomLevel, | 790 EXPECT_EQ(kZoomLevel, |
790 content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents))); | 791 content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents))); |
791 | 792 |
792 // Test chrome.tabs.getZoom(). | 793 // Test chrome.tabs.getZoom(). |
793 zoom_factor = -1; | 794 zoom_factor = -1; |
794 EXPECT_TRUE(RunGetZoom(tab_id, &zoom_factor)); | 795 EXPECT_TRUE(RunGetZoom(tab_id, &zoom_factor)); |
795 EXPECT_EQ(kZoomLevel, zoom_factor); | 796 EXPECT_EQ(kZoomLevel, zoom_factor); |
796 } | 797 } |
797 | 798 |
798 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, ZoomSettings) { | 799 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, ZoomSettings) { |
799 const char kNewTestTabArgsA[] = "http://hostA/"; | 800 // In this test we need two URLs that (1) represent real pages (i.e. they |
800 const char kNewTestTabArgsB[] = "http://hostB/"; | 801 // load without causing an error page load), (2) have different domains, and |
| 802 // (3) are zoomable by the extension API (this last condition rules out |
| 803 // chrome:// urls). We achieve this by noting that about:blank meets these |
| 804 // requirements, allowing us to spin up a spawned http server on localhost to |
| 805 // get the other domain. |
| 806 net::SpawnedTestServer http_server( |
| 807 net::SpawnedTestServer::TYPE_HTTP, |
| 808 net::SpawnedTestServer::kLocalhost, |
| 809 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 810 ASSERT_TRUE(http_server.Start()); |
801 | 811 |
802 GURL url_A(kNewTestTabArgsA); | 812 GURL url_A = http_server.GetURL("files/simple.html"); |
803 GURL url_B(kNewTestTabArgsB); | 813 GURL url_B("about:blank"); |
804 | 814 |
805 // Tabs A1 and A2 are navigated to the same origin, while B is navigated | 815 // Tabs A1 and A2 are navigated to the same origin, while B is navigated |
806 // to a different one. | 816 // to a different one. |
807 content::WebContents* web_contents_A1 = OpenUrlAndWaitForLoad(url_A); | 817 content::WebContents* web_contents_A1 = OpenUrlAndWaitForLoad(url_A); |
808 content::WebContents* web_contents_A2 = OpenUrlAndWaitForLoad(url_A); | 818 content::WebContents* web_contents_A2 = OpenUrlAndWaitForLoad(url_A); |
809 content::WebContents* web_contents_B = OpenUrlAndWaitForLoad(url_B); | 819 content::WebContents* web_contents_B = OpenUrlAndWaitForLoad(url_B); |
810 | 820 |
811 int tab_id_A1 = ExtensionTabUtil::GetTabId(web_contents_A1); | 821 int tab_id_A1 = ExtensionTabUtil::GetTabId(web_contents_A1); |
812 int tab_id_A2 = ExtensionTabUtil::GetTabId(web_contents_A2); | 822 int tab_id_A2 = ExtensionTabUtil::GetTabId(web_contents_A2); |
813 int tab_id_B = ExtensionTabUtil::GetTabId(web_contents_B); | 823 int tab_id_B = ExtensionTabUtil::GetTabId(web_contents_B); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 // Test chrome.tabs.setZoom(). | 915 // Test chrome.tabs.setZoom(). |
906 error = RunSetZoomExpectError(tab_id, 3.14159); | 916 error = RunSetZoomExpectError(tab_id, 3.14159); |
907 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 917 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
908 | 918 |
909 // chrome.tabs.setZoomSettings(). | 919 // chrome.tabs.setZoomSettings(). |
910 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 920 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
911 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 921 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
912 } | 922 } |
913 | 923 |
914 } // namespace extensions | 924 } // namespace extensions |
OLD | NEW |