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

Unified Diff: chrome/browser/external_extension_browsertest.cc

Issue 10091025: Convert the external extension ui_test to a browser_test. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/external_extension_browsertest.cc
===================================================================
--- chrome/browser/external_extension_browsertest.cc (revision 132499)
+++ chrome/browser/external_extension_browsertest.cc (working copy)
@@ -2,139 +2,86 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "base/string_util.h"
-#include "base/test/test_timeouts.h"
-#include "chrome/app/chrome_command_ids.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/url_constants.h"
-#include "chrome/test/automation/automation_proxy.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/ui/ui_test.h"
-#include "net/base/escape.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/url_constants.h"
#include "net/test/test_server.h"
-struct IsSearchProviderTestData;
+namespace {
-class SearchProviderTest : public UITest {
- protected:
- SearchProviderTest();
-
- IsSearchProviderTestData StartIsSearchProviderInstalledTest(
- BrowserProxy* browser_proxy,
- const char* host,
- const char* expected_result);
-
- void FinishIsSearchProviderInstalledTest(
- const IsSearchProviderTestData& data);
-
- net::TestServer test_server_;
- GURL search_provider_test_url_;
- bool test_server_started_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
-};
-
-SearchProviderTest::SearchProviderTest()
- : test_server_(net::TestServer::TYPE_HTTP,
- net::TestServer::kLocalhost,
- FilePath(FILE_PATH_LITERAL("chrome/test/data"))),
- test_server_started_(false) {
- // The test_server is started in the constructor (rather than the test body)
- // so the mapping rules below can include the ephemeral port number.
- test_server_started_ = test_server_.Start();
- if (!test_server_started_)
- return;
-
- // Map all hosts to our local server.
- std::string host_rule("MAP * " + test_server_.host_port_pair().ToString());
- launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule);
-
- // Get the url for the test page.
- search_provider_test_url_ =
- test_server_.GetURL("files/is_search_provider_installed.html");
-}
-
struct IsSearchProviderTestData {
- IsSearchProviderTestData() {
+ IsSearchProviderTestData() : tab(NULL) {}
+ IsSearchProviderTestData(content::WebContents* t, std::string h, GURL url)
+ : tab(t), host(h), test_url(url) {
}
- IsSearchProviderTestData(TabProxy* t,
- std::string h,
- GURL url)
- : tab(t),
- host(h),
- test_url(url) {
- }
-
- scoped_refptr<TabProxy> tab;
+ content::WebContents* 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();
- }
+class SearchProviderTest : public InProcessBrowserTest {
+ protected:
+ SearchProviderTest() {}
- scoped_refptr<TabProxy> tab(browser_proxy->GetTab(num_tabs));
- if (!tab.get()) {
- ADD_FAILURE() << "BrowserProxy::GetTab for the new tab failed.";
- return IsSearchProviderTestData();
- }
+ virtual void SetUpCommandLine(CommandLine* command_line) {
+ ASSERT_TRUE(test_server()->Start());
- // Go to the test page.
- GURL test_url(std::string("http://") + host +
- search_provider_test_url_.path() + "#" + expected_result);
- EXPECT_TRUE(tab->NavigateToURLAsync(test_url));
+ // Map all hosts to our local server.
+ std::string host_rule(
+ "MAP * " + test_server()->host_port_pair().ToString());
+ command_line->AppendSwitchASCII(switches::kHostRules, host_rule);
+ // Use no proxy or otherwise this test will fail on a machine that has a
+ // proxy configured.
+ command_line->AppendSwitch(switches::kNoProxyServer);
- // Bundle up information needed to verify the result.
- return IsSearchProviderTestData(tab, host, test_url);
-}
+ // Get the url for the test page.
+ search_provider_test_url_ =
+ test_server()->GetURL("files/is_search_provider_installed.html");
+ }
-void SearchProviderTest::FinishIsSearchProviderInstalledTest(
- const IsSearchProviderTestData& data) {
- ASSERT_TRUE(data.tab.get());
+ IsSearchProviderTestData StartIsSearchProviderInstalledTest(
+ Browser* browser,
+ const char* host,
+ const char* expected_result) {
+ GURL test_url(std::string("http://") + host +
+ search_provider_test_url_.path() + "#" + expected_result);
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser, test_url, NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
- std::string cookie_name = data.host + "testResult";
- std::string escaped_value =
- WaitUntilCookieNonEmpty(data.tab,
- data.test_url,
- cookie_name.c_str(),
- TestTimeouts::action_max_timeout_ms());
+ // Bundle up information needed to verify the result.
+ content::WebContents* tab = browser->GetSelectedWebContents();
+ return IsSearchProviderTestData(tab, host, test_url);
+ }
- // Unescapes and normalizes the actual result.
- std::string value = net::UnescapeURLComponent(
- escaped_value,
- net::UnescapeRule::NORMAL | net::UnescapeRule::SPACES |
- net::UnescapeRule::URL_SPECIAL_CHARS | net::UnescapeRule::CONTROL_CHARS);
- value += "\n";
- ReplaceSubstringsAfterOffset(&value, 0, "\r", "");
- EXPECT_STREQ("1\n", value.c_str());
- EXPECT_TRUE(data.tab->Close(true));
-}
+ void FinishIsSearchProviderInstalledTest(
+ const IsSearchProviderTestData& data) {
+ string16 title = data.tab->GetTitle();
+ if (title.empty()) {
+ ui_test_utils::TitleWatcher title_watcher(data.tab, ASCIIToUTF16("OK"));
+ title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
+ title = title_watcher.WaitAndGetTitle();
+ }
+ EXPECT_EQ(ASCIIToUTF16("OK"), title);
+ }
-// Flaky on XP debug. http://crbug.com/62777
-#if defined(OS_WIN)
-#define MAYBE_TestIsSearchProviderInstalled DISABLED_TestIsSearchProviderInstalled
-#else
-#define MAYBE_TestIsSearchProviderInstalled TestIsSearchProviderInstalled
-#endif
-TEST_F(SearchProviderTest, MAYBE_TestIsSearchProviderInstalled) {
- ASSERT_TRUE(test_server_started_);
+ GURL search_provider_test_url_;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
+};
+
+// If this flakes on Windows, use http://crbug.com/62777
+IN_PROC_BROWSER_TEST_F(SearchProviderTest, TestIsSearchProviderInstalled) {
// 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,
@@ -150,21 +97,17 @@
IsSearchProviderTestData test_data[2 * arraysize(test_hosts)];
// 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]);
+ browser(), test_hosts[i], expected_results[i]);
FinishIsSearchProviderInstalledTest(test_data[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());
+ Browser* incognito_browser = CreateIncognitoBrowser();
for (size_t i = 0; i < arraysize(test_hosts); ++i) {
test_data[i + arraysize(test_hosts)] = StartIsSearchProviderInstalledTest(
- incognito, test_hosts[i], "0");
+ incognito_browser, test_hosts[i], "0");
FinishIsSearchProviderInstalledTest(test_data[i + arraysize(test_hosts)]);
}
@@ -181,13 +124,13 @@
#endif
}
-TEST_F(SearchProviderTest, TestIsSearchProviderInstalledWithException) {
+IN_PROC_BROWSER_TEST_F(SearchProviderTest,
+ TestIsSearchProviderInstalledWithException) {
// Change the url for the test page to one that throws an exception when
// toString is called on the argument given to isSearchProviderInstalled.
- search_provider_test_url_ = test_server_.GetURL(
+ search_provider_test_url_ = test_server()->GetURL(
"files/is_search_provider_installed_with_exception.html");
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
FinishIsSearchProviderInstalledTest(StartIsSearchProviderInstalledTest(
- browser, "www.google.com", ""));
+ browser(), "www.google.com", ""));
}
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698