| Index: chrome/renderer/external_extension_uitest.cc
|
| diff --git a/chrome/renderer/external_extension_uitest.cc b/chrome/renderer/external_extension_uitest.cc
|
| index 00784a885c923a636ae94e6a4c4ed463d2c0513c..bb6b778963322fe0715911133190e1eea4f34cab 100644
|
| --- a/chrome/renderer/external_extension_uitest.cc
|
| +++ b/chrome/renderer/external_extension_uitest.cc
|
| @@ -4,22 +4,31 @@
|
|
|
| #include "chrome/app/chrome_dll_resource.h"
|
| #include "chrome/common/chrome_switches.h"
|
| +#include "chrome/common/url_constants.h"
|
| #include "chrome/test/automation/tab_proxy.h"
|
| #include "chrome/test/ui/ui_layout_test.h"
|
| #include "chrome/test/ui_test_utils.h"
|
| #include "net/base/escape.h"
|
| #include "net/test/test_server.h"
|
|
|
| +struct IsSearchProviderTestData;
|
| +
|
| class SearchProviderTest : public UITest {
|
| protected:
|
| SearchProviderTest();
|
|
|
| - void TestIsSearchProviderInstalledForHost(
|
| - TabProxy* tab,
|
| + IsSearchProviderTestData StartIsSearchProviderInstalledTest(
|
| + BrowserProxy* browser_proxy,
|
| const char* host,
|
| const char* expected_result);
|
|
|
| + void FinishIsSearchProviderInstalledTest(
|
| + const IsSearchProviderTestData& data);
|
| +
|
| net::TestServer test_server_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
|
| };
|
|
|
| SearchProviderTest::SearchProviderTest()
|
| @@ -33,49 +42,112 @@ SearchProviderTest::SearchProviderTest()
|
| launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule);
|
| }
|
|
|
| -void SearchProviderTest::TestIsSearchProviderInstalledForHost(
|
| - TabProxy* tab,
|
| +struct IsSearchProviderTestData {
|
| + IsSearchProviderTestData() {
|
| + }
|
| +
|
| + IsSearchProviderTestData(TabProxy* t,
|
| + std::string h,
|
| + GURL url)
|
| + : tab(t),
|
| + host(h),
|
| + test_url(url) {
|
| + }
|
| +
|
| + scoped_refptr<TabProxy> tab;
|
| + std::string host;
|
| + GURL test_url;
|
| +};
|
| +
|
| +IsSearchProviderTestData SearchProviderTest::StartIsSearchProviderInstalledTest(
|
| + BrowserProxy* browser_proxy,
|
| const char* host,
|
| const char* expected_result) {
|
| + // Set-up a new tab for the navigation.
|
| + int num_tabs = 0;
|
| + if (!browser_proxy->GetTabCount(&num_tabs)) {
|
| + ADD_FAILURE() << "BrowserProxy::GetTabCount failed.";
|
| + return IsSearchProviderTestData();
|
| + }
|
| +
|
| + GURL blank(chrome::kAboutBlankURL);
|
| + if (!browser_proxy->AppendTab(blank)) {
|
| + ADD_FAILURE() << "BrowserProxy::AppendTab failed.";
|
| + return IsSearchProviderTestData();
|
| + }
|
| +
|
| + scoped_refptr<TabProxy> tab(browser_proxy->GetTab(num_tabs));
|
| + if (!tab.get()) {
|
| + ADD_FAILURE() << "BrowserProxy::GetTab for the new tab failed.";
|
| + return IsSearchProviderTestData();
|
| + }
|
| +
|
| + // Go to the test page.
|
| GURL local_url =
|
| test_server_.GetURL("files/is_search_provider_installed.html");
|
| GURL test_url(std::string("http://") + host + local_url.path() +
|
| "#" + expected_result);
|
| - EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url));
|
| - std::string cookie_name = std::string(host) + "testResult";
|
| + EXPECT_TRUE(tab->NavigateToURLAsync(test_url));
|
| +
|
| + // Bundle up information needed to verify the result.
|
| + return IsSearchProviderTestData(tab, host, test_url);
|
| +}
|
| +
|
| +void SearchProviderTest::FinishIsSearchProviderInstalledTest(
|
| + const IsSearchProviderTestData& data) {
|
| + ASSERT_TRUE(data.tab.get());
|
| +
|
| + std::string cookie_name = data.host + "testResult";
|
| std::string escaped_value =
|
| - WaitUntilCookieNonEmpty(tab, test_url,
|
| + WaitUntilCookieNonEmpty(data.tab, data.test_url,
|
| cookie_name.c_str(), action_max_timeout_ms());
|
|
|
| // Unescapes and normalizes the actual result.
|
| - std::string value = UnescapeURLComponent(escaped_value,
|
| + std::string value = UnescapeURLComponent(
|
| + escaped_value,
|
| UnescapeRule::NORMAL | UnescapeRule::SPACES |
|
| - UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS);
|
| + UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS);
|
| value += "\n";
|
| ReplaceSubstringsAfterOffset(&value, 0, "\r", "");
|
| EXPECT_STREQ("1\n", value.c_str());
|
| }
|
|
|
| -// Verify the default search provider, other installed search provider, and
|
| -// one not installed as well.
|
| TEST_F(SearchProviderTest, DISABLED_TestIsSearchProviderInstalled) {
|
| ASSERT_TRUE(test_server_.Start());
|
|
|
| - scoped_refptr<TabProxy> tab(GetActiveTab());
|
| - ASSERT_TRUE(tab.get());
|
| - TestIsSearchProviderInstalledForHost(tab, "www.google.com", "2");
|
| - TestIsSearchProviderInstalledForHost(tab, "www.bing.com", "1");
|
| - TestIsSearchProviderInstalledForHost(tab, "localhost", "0");
|
| + // Use the default search provider, other installed search provider, and
|
| + // one not installed as well. (Note that yahoo isn't tested because the
|
| + // its host name varies a lot for different locales unlike Google and Bing,
|
| + // which would make the test fail depending on the machine's locale.)
|
| + const char* test_hosts[] = { "www.google.com",
|
| + "www.bing.com",
|
| + "localhost" };
|
| + const char* expected_results[] = { "2",
|
| + "1",
|
| + "0" };
|
| + COMPILE_ASSERT(arraysize(test_hosts) == arraysize(expected_results),
|
| + there_should_be_a_result_for_each_host);
|
| + IsSearchProviderTestData test_data[2 * arraysize(test_hosts)];
|
|
|
| - // Verify that there are no search providers reported in incognito mode.
|
| + // Start results for the normal mode.
|
| scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
|
| ASSERT_TRUE(browser.get());
|
| + for (size_t i = 0; i < arraysize(test_hosts); ++i) {
|
| + test_data[i] = StartIsSearchProviderInstalledTest(
|
| + browser, test_hosts[i], expected_results[i]);
|
| + }
|
| +
|
| + // Start tests for incognito mode (and verify the result is 0).
|
| ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW));
|
| scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1));
|
| ASSERT_TRUE(incognito.get());
|
| - scoped_refptr<TabProxy> incognito_tab(incognito->GetTab(0));
|
| - ASSERT_TRUE(incognito_tab.get());
|
| - TestIsSearchProviderInstalledForHost(incognito_tab, "www.google.com", "0");
|
| - TestIsSearchProviderInstalledForHost(incognito_tab, "www.bing.com", "0");
|
| - TestIsSearchProviderInstalledForHost(incognito_tab, "localhost", "0");
|
| + for (size_t i = 0; i < arraysize(test_hosts); ++i) {
|
| + test_data[i + arraysize(test_hosts)] = StartIsSearchProviderInstalledTest(
|
| + incognito, test_hosts[i], "0");
|
| + }
|
| +
|
| + // Do the verification.
|
| + for (size_t i = 0; i < arraysize(test_hosts); ++i) {
|
| + FinishIsSearchProviderInstalledTest(test_data[i]);
|
| + }
|
| }
|
|
|