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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log_browsertest.cc

Issue 16268017: GTTF: convert some tests in chrome to use EmbeddedTestServer patch nr 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "chrome/browser/extensions/activity_log/activity_log.h" 6 #include "chrome/browser/extensions/activity_log/activity_log.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_browsertest.h" 8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/prerender/prerender_handle.h" 9 #include "chrome/browser/prerender/prerender_handle.h"
10 #include "chrome/browser/prerender/prerender_manager.h" 10 #include "chrome/browser/prerender/prerender_manager.h"
11 #include "chrome/browser/prerender/prerender_manager_factory.h" 11 #include "chrome/browser/prerender/prerender_manager_factory.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "content/public/test/browser_test_utils.h" 16 #include "content/public/test/browser_test_utils.h"
17 #include "net/dns/mock_host_resolver.h" 17 #include "net/dns/mock_host_resolver.h"
18 #include "net/test/embedded_test_server/embedded_test_server.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 // Used to fire all of the listeners on the test buttons. 22 // Used to fire all of the listeners on the test buttons.
22 static const char kScriptBeginClickingTestButtons[] = 23 static const char kScriptBeginClickingTestButtons[] =
23 "(function() {" 24 "(function() {"
24 " setRunningAsRobot();" 25 " setRunningAsRobot();"
25 " beginClickingTestButtons();" 26 " beginClickingTestButtons();"
26 "})();"; 27 "})();";
27 28
28 class ActivityLogExtensionTest : public ExtensionApiTest { 29 class ActivityLogExtensionTest : public ExtensionApiTest {
29 protected: 30 protected:
30 // Make sure the activity log is turned on. 31 // Make sure the activity log is turned on.
31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
32 ExtensionBrowserTest::SetUpCommandLine(command_line); 33 ExtensionBrowserTest::SetUpCommandLine(command_line);
33 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging); 34 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging);
34 command_line->AppendSwitch(switches::kEnableExtensionActivityLogTesting); 35 command_line->AppendSwitch(switches::kEnableExtensionActivityLogTesting);
35 command_line->AppendSwitchASCII(switches::kPrerenderMode, 36 command_line->AppendSwitchASCII(switches::kPrerenderMode,
36 switches::kPrerenderModeSwitchValueEnabled); 37 switches::kPrerenderModeSwitchValueEnabled);
37 } 38 }
38 // Start the test server, load the activity log extension, and navigate 39 // Start the test server, load the activity log extension, and navigate
39 // the browser to the options page of the extension. 40 // the browser to the options page of the extension.
40 TabStripModel* StartTestServerAndInitialize() { 41 TabStripModel* StartEmbeddedTestServerAndInitialize() {
41 host_resolver()->AddRule("*", "127.0.0.1"); 42 host_resolver()->AddRule("*", "127.0.0.1");
42 StartTestServer(); 43 StartEmbeddedTestServer();
43 44
44 // Get the extension (chrome/test/data/extensions/activity_log) 45 // Get the extension (chrome/test/data/extensions/activity_log)
45 const extensions::Extension* ext = 46 const extensions::Extension* ext =
46 LoadExtension(test_data_dir_.AppendASCII("activity_log")); 47 LoadExtension(test_data_dir_.AppendASCII("activity_log"));
47 CHECK(ext); 48 CHECK(ext);
48 49
49 // Open up the Options page. 50 // Open up the Options page.
50 ui_test_utils::NavigateToURL( 51 ui_test_utils::NavigateToURL(
51 browser(), 52 browser(),
52 GURL("chrome-extension://" + ext->id() + "/options.html")); 53 GURL("chrome-extension://" + ext->id() + "/options.html"));
(...skipping 21 matching lines...) Expand all
74 }; 75 };
75 76
76 #if defined(OS_WIN) 77 #if defined(OS_WIN)
77 // TODO(ataly): test flaky on windows. See Bug: crbug.com/245594 78 // TODO(ataly): test flaky on windows. See Bug: crbug.com/245594
78 #define MAYBE_ChromeEndToEnd DISABLED_ChromeEndToEnd 79 #define MAYBE_ChromeEndToEnd DISABLED_ChromeEndToEnd
79 #else 80 #else
80 #define MAYBE_ChromeEndToEnd ChromeEndToEnd 81 #define MAYBE_ChromeEndToEnd ChromeEndToEnd
81 #endif 82 #endif
82 83
83 IN_PROC_BROWSER_TEST_F(ActivityLogExtensionTest, MAYBE_ChromeEndToEnd) { 84 IN_PROC_BROWSER_TEST_F(ActivityLogExtensionTest, MAYBE_ChromeEndToEnd) {
84 TabStripModel* tab_strip = StartTestServerAndInitialize(); 85 TabStripModel* tab_strip = StartEmbeddedTestServerAndInitialize();
85 ResultCatcher catcher; 86 ResultCatcher catcher;
86 // Set the default URL so that is has the correct port number. 87 // Set the default URL so that is has the correct port number.
87 net::HostPortPair host_port = test_server()->host_port_pair();
88 std::string url_setting_script = base::StringPrintf( 88 std::string url_setting_script = base::StringPrintf(
89 "defaultUrl = \'http://www.google.com:%d\';", host_port.port()); 89 "defaultUrl = \'http://www.google.com:%d\';",
90 embedded_test_server()->port());
90 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(), 91 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(),
91 url_setting_script)); 92 url_setting_script));
92 // Set the test buttons array 93 // Set the test buttons array
93 std::string test_buttons_setting_script = 94 std::string test_buttons_setting_script =
94 "setTestButtons(document.getElementsByName('chromeButton'))"; 95 "setTestButtons(document.getElementsByName('chromeButton'))";
95 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(), 96 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(),
96 test_buttons_setting_script)); 97 test_buttons_setting_script));
97 // Run the test by firing all the buttons. Wait until completion. 98 // Run the test by firing all the buttons. Wait until completion.
98 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(), 99 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(),
99 kScriptBeginClickingTestButtons)); 100 kScriptBeginClickingTestButtons));
100 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 101 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
101 } 102 }
102 103
103 #if defined(OS_WIN) || defined(OS_MACOSX) 104 #if defined(OS_WIN) || defined(OS_MACOSX)
104 // TODO(ataly): test flaky on windows and Mac. See Bug: crbug.com/245594 105 // TODO(ataly): test flaky on windows and Mac. See Bug: crbug.com/245594
105 #define MAYBE_DOMEndToEnd DISABLED_DOMEndToEnd 106 #define MAYBE_DOMEndToEnd DISABLED_DOMEndToEnd
106 #else 107 #else
107 #define MAYBE_DOMEndToEnd DOMEndToEnd 108 #define MAYBE_DOMEndToEnd DOMEndToEnd
108 #endif 109 #endif
109 110
110 IN_PROC_BROWSER_TEST_F(ActivityLogExtensionTest, MAYBE_DOMEndToEnd) { 111 IN_PROC_BROWSER_TEST_F(ActivityLogExtensionTest, MAYBE_DOMEndToEnd) {
111 TabStripModel* tab_strip = StartTestServerAndInitialize(); 112 TabStripModel* tab_strip = StartEmbeddedTestServerAndInitialize();
112 ResultCatcher catcher; 113 ResultCatcher catcher;
113 // Set the default URL so that is has the correct port number. 114 // Set the default URL so that is has the correct port number.
114 net::HostPortPair host_port = test_server()->host_port_pair();
115 std::string url_setting_script = base::StringPrintf( 115 std::string url_setting_script = base::StringPrintf(
116 "defaultUrl = \'http://www.google.com:%d\';", host_port.port()); 116 "defaultUrl = \'http://www.google.com:%d\';",
117 embedded_test_server()->port());
117 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(), 118 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(),
118 url_setting_script)); 119 url_setting_script));
119 // Set the test buttons array 120 // Set the test buttons array
120 std::string test_buttons_setting_script = 121 std::string test_buttons_setting_script =
121 "setTestButtons(document.getElementsByName('domButton'))"; 122 "setTestButtons(document.getElementsByName('domButton'))";
122 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(), 123 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(),
123 test_buttons_setting_script)); 124 test_buttons_setting_script));
124 // Run the test by firing all the buttons. Wait until completion. 125 // Run the test by firing all the buttons. Wait until completion.
125 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(), 126 ASSERT_TRUE(content::ExecuteScript(tab_strip->GetActiveWebContents(),
126 kScriptBeginClickingTestButtons)); 127 kScriptBeginClickingTestButtons));
127 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 128 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
128 } 129 }
129 130
130 IN_PROC_BROWSER_TEST_F(ActivityLogExtensionTest, ExtensionPrerender) { 131 IN_PROC_BROWSER_TEST_F(ActivityLogExtensionTest, ExtensionPrerender) {
131 host_resolver()->AddRule("*", "127.0.0.1"); 132 host_resolver()->AddRule("*", "127.0.0.1");
132 StartTestServer(); 133 StartEmbeddedTestServer();
133 int port = test_server()->host_port_pair().port(); 134 int port = embedded_test_server()->port();
134 135
135 // Get the extension (chrome/test/data/extensions/activity_log) 136 // Get the extension (chrome/test/data/extensions/activity_log)
136 const Extension* ext = 137 const Extension* ext =
137 LoadExtension(test_data_dir_.AppendASCII("activity_log")); 138 LoadExtension(test_data_dir_.AppendASCII("activity_log"));
138 ASSERT_TRUE(ext); 139 ASSERT_TRUE(ext);
139 140
140 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); 141 ActivityLog* activity_log = ActivityLog::GetInstance(profile());
141 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); 142 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM);
142 ASSERT_TRUE(activity_log); 143 ASSERT_TRUE(activity_log);
143 144
(...skipping 29 matching lines...) Expand all
173 174
174 activity_log->GetActions( 175 activity_log->GetActions(
175 ext->id(), 0, base::Bind( 176 ext->id(), 0, base::Bind(
176 ActivityLogExtensionTest::Prerender_Arguments, port)); 177 ActivityLogExtensionTest::Prerender_Arguments, port));
177 178
178 // Allow invocation of Prerender_Arguments 179 // Allow invocation of Prerender_Arguments
179 base::MessageLoop::current()->Run(); 180 base::MessageLoop::current()->Run();
180 } 181 }
181 182
182 } // namespace extensions 183 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/active_tab_apitest.cc ('k') | chrome/browser/extensions/ad_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698