Commit 19da16a9 authored by creis@chromium.org's avatar creis@chromium.org

Fix flakiness by removing GetLastActive from extension browser tests.

BUG=108853
TEST=AppApiTest.* and ExtensionBrowserTest.* no longer flaky


Review URL: https://chromiumcodereview.appspot.com/10412047

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138503 0039d316-1c4b-4281-b951-d872f2087c98
parent 3e31a0ad
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/scoped_temp_dir.h" #include "base/scoped_temp_dir.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/app_shortcut_manager.h" #include "chrome/browser/extensions/app_shortcut_manager.h"
#include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/crx_installer.h"
...@@ -28,6 +29,8 @@ ...@@ -28,6 +29,8 @@
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
...@@ -460,6 +463,53 @@ bool ExtensionBrowserTest::WaitForExtensionCrash( ...@@ -460,6 +463,53 @@ bool ExtensionBrowserTest::WaitForExtensionCrash(
return (service->GetExtensionById(extension_id, true) == NULL); return (service->GetExtensionById(extension_id, true) == NULL);
} }
void ExtensionBrowserTest::OpenWindow(content::WebContents* contents,
const GURL& url,
bool newtab_process_should_equal_opener,
content::WebContents** newtab_result) {
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
contents->GetRenderViewHost(), L"",
L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
// The above window.open call is not user-initiated, so it will create
// a popup window instead of a new tab in current window.
// The stop notification will come from the new tab.
observer.Wait();
content::NavigationController* controller =
content::Source<content::NavigationController>(observer.source()).ptr();
content::WebContents* newtab = controller->GetWebContents();
ASSERT_TRUE(newtab);
EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL());
if (newtab_process_should_equal_opener)
EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
else
EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
if (newtab_result)
*newtab_result = newtab;
}
void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents,
const GURL& url) {
bool result = false;
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
contents->GetRenderViewHost(), L"",
L"window.addEventListener('unload', function() {"
L" window.domAutomationController.send(true);"
L"}, false);"
L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
&result));
ASSERT_TRUE(result);
observer.Wait();
EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL());
}
void ExtensionBrowserTest::Observe( void ExtensionBrowserTest::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
namespace extensions { namespace extensions {
class Extension; class Extension;
...@@ -136,6 +137,17 @@ class ExtensionBrowserTest ...@@ -136,6 +137,17 @@ class ExtensionBrowserTest
// crashed. // crashed.
bool WaitForExtensionCrash(const std::string& extension_id); bool WaitForExtensionCrash(const std::string& extension_id);
// Simulates a page calling window.open on an URL and waits for the
// navigation.
void OpenWindow(content::WebContents* contents,
const GURL& url,
bool newtab_process_should_equal_opener,
content::WebContents** newtab_result);
// Simulates a page navigating itself to an URL and waits for the
// navigation.
void NavigateInRenderer(content::WebContents* contents, const GURL& url);
// content::NotificationObserver // content::NotificationObserver
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
......
...@@ -649,44 +649,18 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) { ...@@ -649,44 +649,18 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) {
EXPECT_TRUE(result); EXPECT_TRUE(result);
} }
// Helper function for common code shared by the 3 WindowOpen tests below.
static void WindowOpenHelper(Browser* browser, const GURL& start_url,
const std::string& newtab_url,
WebContents** newtab_result) {
ui_test_utils::NavigateToURL(browser, start_url);
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
browser->GetSelectedWebContents()->GetRenderViewHost(), L"",
L"window.open('" + UTF8ToWide(newtab_url) + L"');"));
// Now the active tab in last active window should be the new tab.
Browser* last_active_browser = BrowserList::GetLastActive();
EXPECT_TRUE(last_active_browser);
WebContents* newtab = last_active_browser->GetSelectedWebContents();
EXPECT_TRUE(newtab);
GURL expected_url = start_url.Resolve(newtab_url);
observer.Wait();
EXPECT_EQ(expected_url,
newtab->GetController().GetLastCommittedEntry()->GetURL());
if (newtab_result)
*newtab_result = newtab;
}
// Tests that an extension page can call window.open to an extension URL and // Tests that an extension page can call window.open to an extension URL and
// the new window has extension privileges. // the new window has extension privileges.
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
GURL start_url(std::string("chrome-extension://") +
last_loaded_extension_id_ + "/test.html");
ui_test_utils::NavigateToURL(browser(), start_url);
WebContents* newtab; WebContents* newtab;
ASSERT_NO_FATAL_FAILURE(WindowOpenHelper( ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetSelectedWebContents(),
browser(), start_url.Resolve("newtab.html"), true, &newtab));
GURL(std::string("chrome-extension://") + last_loaded_extension_id_ +
"/test.html"),
"newtab.html", &newtab));
bool result = false; bool result = false;
ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
...@@ -700,11 +674,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { ...@@ -700,11 +674,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
ASSERT_NO_FATAL_FAILURE(WindowOpenHelper( GURL start_url(std::string("chrome-extension://") +
browser(), last_loaded_extension_id_ + "/test.html");
GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + ui_test_utils::NavigateToURL(browser(), start_url);
"/test.html"), ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetSelectedWebContents(),
"chrome-extension://thisissurelynotavalidextensionid/newtab.html", NULL)); GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
false, NULL));
// If we got to this point, we didn't crash, so we're good. // If we got to this point, we didn't crash, so we're good.
} }
...@@ -717,13 +692,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { ...@@ -717,13 +692,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
WebContents* newtab; WebContents* newtab;
ASSERT_NO_FATAL_FAILURE(WindowOpenHelper( ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetSelectedWebContents(),
browser(), GURL(std::string("chrome-extension://") + last_loaded_extension_id_ +
GURL("about:blank"), "/newtab.html"), false, &newtab));
std::string("chrome-extension://") + last_loaded_extension_id_ +
"/newtab.html",
&newtab));
// Extension API should succeed. // Extension API should succeed.
bool result = false; bool result = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment