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

Side by Side Diff: chrome/renderer/external_extension_uitest.cc

Issue 3159030: Speed up the test for IsSearchProviderInstalled by making it run multiple test pages in parallel. (Closed)
Patch Set: Created 10 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/app/chrome_dll_resource.h" 5 #include "chrome/app/chrome_dll_resource.h"
6 #include "chrome/common/chrome_switches.h" 6 #include "chrome/common/chrome_switches.h"
7 #include "chrome/common/url_constants.h"
7 #include "chrome/test/automation/tab_proxy.h" 8 #include "chrome/test/automation/tab_proxy.h"
8 #include "chrome/test/ui/ui_layout_test.h" 9 #include "chrome/test/ui/ui_layout_test.h"
9 #include "chrome/test/ui_test_utils.h" 10 #include "chrome/test/ui_test_utils.h"
10 #include "net/base/escape.h" 11 #include "net/base/escape.h"
11 #include "net/test/test_server.h" 12 #include "net/test/test_server.h"
12 13
14 struct IsSearchProviderTestData;
15
13 class SearchProviderTest : public UITest { 16 class SearchProviderTest : public UITest {
14 protected: 17 protected:
15 SearchProviderTest(); 18 SearchProviderTest();
16 19
17 void TestIsSearchProviderInstalledForHost( 20 IsSearchProviderTestData StartIsSearchProviderInstalledTest(
18 TabProxy* tab, 21 BrowserProxy* browser_proxy,
19 const char* host, 22 const char* host,
20 const char* expected_result); 23 const char* expected_result);
21 24
25 void FinishIsSearchProviderInstalledTest(
26 const IsSearchProviderTestData& data);
27
22 net::TestServer test_server_; 28 net::TestServer test_server_;
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
23 }; 32 };
24 33
25 SearchProviderTest::SearchProviderTest() 34 SearchProviderTest::SearchProviderTest()
26 : test_server_(net::TestServer::TYPE_HTTP, 35 : test_server_(net::TestServer::TYPE_HTTP,
27 FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { 36 FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
28 // Enable the search provider additions. 37 // Enable the search provider additions.
29 launch_arguments_.AppendSwitch(switches::kEnableSearchProviderApiV2); 38 launch_arguments_.AppendSwitch(switches::kEnableSearchProviderApiV2);
30 39
31 // Map all hosts to our local server. 40 // Map all hosts to our local server.
32 std::string host_rule("MAP * " + test_server_.host_port_pair().ToString()); 41 std::string host_rule("MAP * " + test_server_.host_port_pair().ToString());
33 launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule); 42 launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule);
34 } 43 }
35 44
36 void SearchProviderTest::TestIsSearchProviderInstalledForHost( 45 struct IsSearchProviderTestData {
37 TabProxy* tab, 46 IsSearchProviderTestData() {
47 }
48
49 IsSearchProviderTestData(TabProxy* t,
50 std::string h,
51 GURL url)
52 : tab(t),
53 host(h),
54 test_url(url) {
55 }
56
57 scoped_refptr<TabProxy> tab;
58 std::string host;
59 GURL test_url;
60 };
61
62 IsSearchProviderTestData SearchProviderTest::StartIsSearchProviderInstalledTest(
63 BrowserProxy* browser_proxy,
38 const char* host, 64 const char* host,
39 const char* expected_result) { 65 const char* expected_result) {
66 // Set-up a new tab for the navigation.
67 int num_tabs = 0;
68 if (!browser_proxy->GetTabCount(&num_tabs)) {
69 ADD_FAILURE() << "BrowserProxy::GetTabCount failed.";
70 return IsSearchProviderTestData();
71 }
72
73 GURL blank(chrome::kAboutBlankURL);
74 if (!browser_proxy->AppendTab(blank)) {
75 ADD_FAILURE() << "BrowserProxy::AppendTab failed.";
76 return IsSearchProviderTestData();
77 }
78
79 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(num_tabs));
80 if (!tab.get()) {
81 ADD_FAILURE() << "BrowserProxy::GetTab for the new tab failed.";
82 return IsSearchProviderTestData();
83 }
84
85 // Go to the test page.
40 GURL local_url = 86 GURL local_url =
41 test_server_.GetURL("files/is_search_provider_installed.html"); 87 test_server_.GetURL("files/is_search_provider_installed.html");
42 GURL test_url(std::string("http://") + host + local_url.path() + 88 GURL test_url(std::string("http://") + host + local_url.path() +
43 "#" + expected_result); 89 "#" + expected_result);
44 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); 90 EXPECT_TRUE(tab->NavigateToURLAsync(test_url));
45 std::string cookie_name = std::string(host) + "testResult"; 91
92 // Bundle up information needed to verify the result.
93 return IsSearchProviderTestData(tab, host, test_url);
94 }
95
96 void SearchProviderTest::FinishIsSearchProviderInstalledTest(
97 const IsSearchProviderTestData& data) {
98 ASSERT_TRUE(data.tab.get());
99
100 std::string cookie_name = data.host + "testResult";
46 std::string escaped_value = 101 std::string escaped_value =
47 WaitUntilCookieNonEmpty(tab, test_url, 102 WaitUntilCookieNonEmpty(data.tab, data.test_url,
48 cookie_name.c_str(), action_max_timeout_ms()); 103 cookie_name.c_str(), action_max_timeout_ms());
49 104
50 // Unescapes and normalizes the actual result. 105 // Unescapes and normalizes the actual result.
51 std::string value = UnescapeURLComponent(escaped_value, 106 std::string value = UnescapeURLComponent(
107 escaped_value,
52 UnescapeRule::NORMAL | UnescapeRule::SPACES | 108 UnescapeRule::NORMAL | UnescapeRule::SPACES |
53 UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS); 109 UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS);
54 value += "\n"; 110 value += "\n";
55 ReplaceSubstringsAfterOffset(&value, 0, "\r", ""); 111 ReplaceSubstringsAfterOffset(&value, 0, "\r", "");
56 EXPECT_STREQ("1\n", value.c_str()); 112 EXPECT_STREQ("1\n", value.c_str());
57 } 113 }
58 114
59 // Verify the default search provider, other installed search provider, and
60 // one not installed as well.
61 TEST_F(SearchProviderTest, DISABLED_TestIsSearchProviderInstalled) { 115 TEST_F(SearchProviderTest, DISABLED_TestIsSearchProviderInstalled) {
62 ASSERT_TRUE(test_server_.Start()); 116 ASSERT_TRUE(test_server_.Start());
63 117
64 scoped_refptr<TabProxy> tab(GetActiveTab()); 118 // Use the default search provider, other installed search provider, and
65 ASSERT_TRUE(tab.get()); 119 // one not installed as well. (Note that yahoo isn't tested because the
66 TestIsSearchProviderInstalledForHost(tab, "www.google.com", "2"); 120 // its host name varies a lot for different locales unlike Google and Bing,
67 TestIsSearchProviderInstalledForHost(tab, "www.bing.com", "1"); 121 // which would make the test fail depending on the machine's locale.)
68 TestIsSearchProviderInstalledForHost(tab, "localhost", "0"); 122 const char* test_hosts[] = { "www.google.com",
123 "www.bing.com",
124 "localhost" };
125 const char* expected_results[] = { "2",
126 "1",
127 "0" };
128 COMPILE_ASSERT(arraysize(test_hosts) == arraysize(expected_results),
129 there_should_be_a_result_for_each_host);
130 IsSearchProviderTestData test_data[2 * arraysize(test_hosts)];
69 131
70 // Verify that there are no search providers reported in incognito mode. 132 // Start results for the normal mode.
71 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 133 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
72 ASSERT_TRUE(browser.get()); 134 ASSERT_TRUE(browser.get());
135 for (size_t i = 0; i < arraysize(test_hosts); ++i) {
136 test_data[i] = StartIsSearchProviderInstalledTest(
137 browser, test_hosts[i], expected_results[i]);
138 }
139
140 // Start tests for incognito mode (and verify the result is 0).
73 ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW)); 141 ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW));
74 scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1)); 142 scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1));
75 ASSERT_TRUE(incognito.get()); 143 ASSERT_TRUE(incognito.get());
76 scoped_refptr<TabProxy> incognito_tab(incognito->GetTab(0)); 144 for (size_t i = 0; i < arraysize(test_hosts); ++i) {
77 ASSERT_TRUE(incognito_tab.get()); 145 test_data[i + arraysize(test_hosts)] = StartIsSearchProviderInstalledTest(
78 TestIsSearchProviderInstalledForHost(incognito_tab, "www.google.com", "0"); 146 incognito, test_hosts[i], "0");
79 TestIsSearchProviderInstalledForHost(incognito_tab, "www.bing.com", "0"); 147 }
80 TestIsSearchProviderInstalledForHost(incognito_tab, "localhost", "0"); 148
149 // Do the verification.
150 for (size_t i = 0; i < arraysize(test_hosts); ++i) {
151 FinishIsSearchProviderInstalledTest(test_data[i]);
152 }
81 } 153 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698