Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase bug. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 24 matching lines...) Expand all
35 #include "content/public/common/page_zoom.h" 35 #include "content/public/common/page_zoom.h"
36 #include "content/public/common/url_constants.h" 36 #include "content/public/common/url_constants.h"
37 #include "extensions/browser/api_test_utils.h" 37 #include "extensions/browser/api_test_utils.h"
38 #include "extensions/browser/app_window/app_window.h" 38 #include "extensions/browser/app_window/app_window.h"
39 #include "extensions/browser/app_window/app_window_registry.h" 39 #include "extensions/browser/app_window/app_window_registry.h"
40 #include "extensions/browser/app_window/native_app_window.h" 40 #include "extensions/browser/app_window/native_app_window.h"
41 #include "extensions/common/manifest_constants.h" 41 #include "extensions/common/manifest_constants.h"
42 #include "extensions/common/test_util.h" 42 #include "extensions/common/test_util.h"
43 #include "extensions/test/extension_test_message_listener.h" 43 #include "extensions/test/extension_test_message_listener.h"
44 #include "extensions/test/result_catcher.h" 44 #include "extensions/test/result_catcher.h"
45 #include "net/test/spawned_test_server/spawned_test_server.h" 45 #include "net/test/embedded_test_server/embedded_test_server.h"
46 #include "ui/gfx/geometry/rect.h" 46 #include "ui/gfx/geometry/rect.h"
47 #include "ui/views/widget/widget.h" 47 #include "ui/views/widget/widget.h"
48 #include "ui/views/widget/widget_observer.h" 48 #include "ui/views/widget/widget_observer.h"
49 49
50 namespace extensions { 50 namespace extensions {
51 51
52 namespace keys = tabs_constants; 52 namespace keys = tabs_constants;
53 namespace utils = extension_function_test_utils; 53 namespace utils = extension_function_test_utils;
54 54
55 namespace { 55 namespace {
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 EXPECT_TRUE(content::ZoomValuesEqual( 1588 EXPECT_TRUE(content::ZoomValuesEqual(
1589 new_default_zoom_level, 1589 new_default_zoom_level,
1590 content::ZoomFactorToZoomLevel(observed_zoom_factor))); 1590 content::ZoomFactorToZoomLevel(observed_zoom_factor)));
1591 } 1591 }
1592 1592
1593 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, ZoomSettings) { 1593 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, ZoomSettings) {
1594 // In this test we need two URLs that (1) represent real pages (i.e. they 1594 // In this test we need two URLs that (1) represent real pages (i.e. they
1595 // load without causing an error page load), (2) have different domains, and 1595 // load without causing an error page load), (2) have different domains, and
1596 // (3) are zoomable by the extension API (this last condition rules out 1596 // (3) are zoomable by the extension API (this last condition rules out
1597 // chrome:// urls). We achieve this by noting that about:blank meets these 1597 // chrome:// urls). We achieve this by noting that about:blank meets these
1598 // requirements, allowing us to spin up a spawned http server on localhost to 1598 // requirements, allowing us to spin up an embedded http server on localhost
1599 // get the other domain. 1599 // to get the other domain.
1600 net::SpawnedTestServer http_server( 1600 net::EmbeddedTestServer http_server;
1601 net::SpawnedTestServer::TYPE_HTTP, 1601 http_server.ServeFilesFromSourceDirectory("chrome/test/data");
1602 net::SpawnedTestServer::kLocalhost,
1603 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1604 ASSERT_TRUE(http_server.Start()); 1602 ASSERT_TRUE(http_server.Start());
1605 1603
1606 GURL url_A = http_server.GetURL("files/simple.html"); 1604 GURL url_A = http_server.GetURL("/simple.html");
1607 GURL url_B("about:blank"); 1605 GURL url_B("about:blank");
1608 1606
1609 // Tabs A1 and A2 are navigated to the same origin, while B is navigated 1607 // Tabs A1 and A2 are navigated to the same origin, while B is navigated
1610 // to a different one. 1608 // to a different one.
1611 content::WebContents* web_contents_A1 = OpenUrlAndWaitForLoad(url_A); 1609 content::WebContents* web_contents_A1 = OpenUrlAndWaitForLoad(url_A);
1612 content::WebContents* web_contents_A2 = OpenUrlAndWaitForLoad(url_A); 1610 content::WebContents* web_contents_A2 = OpenUrlAndWaitForLoad(url_A);
1613 content::WebContents* web_contents_B = OpenUrlAndWaitForLoad(url_B); 1611 content::WebContents* web_contents_B = OpenUrlAndWaitForLoad(url_B);
1614 1612
1615 int tab_id_A1 = ExtensionTabUtil::GetTabId(web_contents_A1); 1613 int tab_id_A1 = ExtensionTabUtil::GetTabId(web_contents_A1);
1616 int tab_id_A2 = ExtensionTabUtil::GetTabId(web_contents_A2); 1614 int tab_id_A2 = ExtensionTabUtil::GetTabId(web_contents_A2);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 EXPECT_TRUE(base::MatchPattern(error, keys::kCannotZoomDisabledTabError)); 1653 EXPECT_TRUE(base::MatchPattern(error, keys::kCannotZoomDisabledTabError));
1656 EXPECT_FLOAT_EQ( 1654 EXPECT_FLOAT_EQ(
1657 1.f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A1))); 1655 1.f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A1)));
1658 // We should still be able to zoom A2 though. 1656 // We should still be able to zoom A2 though.
1659 EXPECT_TRUE(RunSetZoom(tab_id_A2, 1.4f)); 1657 EXPECT_TRUE(RunSetZoom(tab_id_A2, 1.4f));
1660 EXPECT_FLOAT_EQ( 1658 EXPECT_FLOAT_EQ(
1661 1.4f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A2))); 1659 1.4f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A2)));
1662 } 1660 }
1663 1661
1664 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, PerTabResetsOnNavigation) { 1662 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, PerTabResetsOnNavigation) {
1665 net::SpawnedTestServer http_server( 1663 net::EmbeddedTestServer http_server;
1666 net::SpawnedTestServer::TYPE_HTTP, 1664 http_server.ServeFilesFromSourceDirectory("chrome/test/data");
1667 net::SpawnedTestServer::kLocalhost,
1668 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1669 ASSERT_TRUE(http_server.Start()); 1665 ASSERT_TRUE(http_server.Start());
1670 1666
1671 GURL url_A = http_server.GetURL("files/simple.html"); 1667 GURL url_A = http_server.GetURL("/simple.html");
1672 GURL url_B("about:blank"); 1668 GURL url_B("about:blank");
1673 1669
1674 content::WebContents* web_contents = OpenUrlAndWaitForLoad(url_A); 1670 content::WebContents* web_contents = OpenUrlAndWaitForLoad(url_A);
1675 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 1671 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
1676 EXPECT_TRUE(RunSetZoomSettings(tab_id, "automatic", "per-tab")); 1672 EXPECT_TRUE(RunSetZoomSettings(tab_id, "automatic", "per-tab"));
1677 1673
1678 std::string mode; 1674 std::string mode;
1679 std::string scope; 1675 std::string scope;
1680 EXPECT_TRUE(RunGetZoomSettings(tab_id, &mode, &scope)); 1676 EXPECT_TRUE(RunGetZoomSettings(tab_id, &mode, &scope));
1681 EXPECT_EQ("automatic", mode); 1677 EXPECT_EQ("automatic", mode);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 EXPECT_TRUE( 1733 EXPECT_TRUE(
1738 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 1734 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
1739 1735
1740 // chrome.tabs.setZoomSettings(). 1736 // chrome.tabs.setZoomSettings().
1741 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); 1737 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab");
1742 EXPECT_TRUE( 1738 EXPECT_TRUE(
1743 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 1739 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
1744 } 1740 }
1745 1741
1746 } // namespace extensions 1742 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698