Commit 30d8a3b9 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Fix flaky webrequest related network service tests in component builds

These tests needed some extra synchronization due to the changes made in
http://crrev.com/c/1139048. These were flaking in component builds.

Bug: 871224
Change-Id: Ibe370f9b9c8ebb94ee1dd21ba204c06e91518057
Reviewed-on: https://chromium-review.googlesource.com/1163987
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580980}
parent 5447538a
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/browser/api/declarative/rules_registry_service.h" #include "extensions/browser/api/declarative/rules_registry_service.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_rules_registry.h" #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registry.h"
...@@ -186,6 +187,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, ...@@ -186,6 +187,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest,
const Extension* extension = InstallExtensionWithUIAutoConfirm( const Extension* extension = InstallExtensionWithUIAutoConfirm(
ext_dir.Pack(), 1 /*+1 installed extension*/, browser()); ext_dir.Pack(), 1 /*+1 installed extension*/, browser());
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
std::string extension_id(extension->id()); std::string extension_id(extension->id());
ASSERT_TRUE(ready.WaitUntilSatisfied()); ASSERT_TRUE(ready.WaitUntilSatisfied());
ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl)); ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl));
...@@ -260,6 +264,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, MAYBE_NoTracesAfterUninstalling) { ...@@ -260,6 +264,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, MAYBE_NoTracesAfterUninstalling) {
const Extension* extension = InstallExtensionWithUIAutoConfirm( const Extension* extension = InstallExtensionWithUIAutoConfirm(
ext_dir.Pack(), 1 /*+1 installed extension*/, browser()); ext_dir.Pack(), 1 /*+1 installed extension*/, browser());
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
std::string extension_id(extension->id()); std::string extension_id(extension->id());
ASSERT_TRUE(ready.WaitUntilSatisfied()); ASSERT_TRUE(ready.WaitUntilSatisfied());
ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl)); ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl));
...@@ -270,6 +277,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, MAYBE_NoTracesAfterUninstalling) { ...@@ -270,6 +277,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, MAYBE_NoTracesAfterUninstalling) {
// 2. Uninstall the extension. Rules are gone and preferences should be empty. // 2. Uninstall the extension. Rules are gone and preferences should be empty.
UninstallExtension(extension_id); UninstallExtension(extension_id);
// Wait for declarative rules to be removed.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl)); ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl));
EXPECT_NE(kTestTitle, GetTitle()); EXPECT_NE(kTestTitle, GetTitle());
EXPECT_EQ(0u, NumberOfRegisteredRules(extension_id)); EXPECT_EQ(0u, NumberOfRegisteredRules(extension_id));
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
...@@ -361,6 +362,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, ReusedActionInstance) { ...@@ -361,6 +362,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, ReusedActionInstance) {
ExtensionTestMessageListener ready("ready", false); ExtensionTestMessageListener ready("ready", false);
const Extension* extension = LoadExtension(ext_dir_.UnpackedPath()); const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const ExtensionAction* page_action = const ExtensionAction* page_action =
ExtensionActionManager::Get(browser()->profile()) ExtensionActionManager::Get(browser()->profile())
->GetPageAction(*extension); ->GetPageAction(*extension);
...@@ -605,6 +609,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, ...@@ -605,6 +609,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
const Extension* extension = LoadExtension(ext_dir_.UnpackedPath()); const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const std::string extension_id = extension->id(); const std::string extension_id = extension->id();
const ExtensionAction* page_action = ExtensionActionManager::Get( const ExtensionAction* page_action = ExtensionActionManager::Get(
browser()->profile())->GetPageAction(*extension); browser()->profile())->GetPageAction(*extension);
...@@ -631,6 +638,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, ...@@ -631,6 +638,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab)); EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab));
ReloadExtension(extension_id); // Invalidates page_action and extension. ReloadExtension(extension_id); // Invalidates page_action and extension.
// Wait for declarative rules to be removed.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
EXPECT_EQ("test_rule", EXPECT_EQ("test_rule",
ExecuteScriptInBackgroundPage(extension_id, kTestRule)); ExecuteScriptInBackgroundPage(extension_id, kTestRule));
// TODO(jyasskin): Apply new rules to existing tabs, without waiting for a // TODO(jyasskin): Apply new rules to existing tabs, without waiting for a
...@@ -641,6 +651,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, ...@@ -641,6 +651,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab)); EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab));
UnloadExtension(extension_id); UnloadExtension(extension_id);
// Wait for declarative rules to be removed.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
NavigateInRenderer(tab, GURL("http://test/")); NavigateInRenderer(tab, GURL("http://test/"));
EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(0)); EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(0));
EXPECT_EQ(0u, extension_action_test_util::GetVisiblePageActionCount(tab)); EXPECT_EQ(0u, extension_action_test_util::GetVisiblePageActionCount(tab));
...@@ -722,6 +735,9 @@ IN_PROC_BROWSER_TEST_P(ShowPageActionWithoutPageActionTest, Test) { ...@@ -722,6 +735,9 @@ IN_PROC_BROWSER_TEST_P(ShowPageActionWithoutPageActionTest, Test) {
scoped_refptr<const Extension> extension = scoped_refptr<const Extension> extension =
loader.LoadExtension(ext_dir_.UnpackedPath()); loader.LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const char kScript[] = const char kScript[] =
"setRules([{\n" "setRules([{\n"
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/common/features/feature_channel.h" #include "extensions/common/features/feature_channel.h"
#include "extensions/test/extension_test_message_listener.h" #include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/test_extension_dir.h" #include "extensions/test/test_extension_dir.h"
...@@ -74,6 +75,9 @@ IN_PROC_BROWSER_TEST_F(SetIconAPITest, Overview) { ...@@ -74,6 +75,9 @@ IN_PROC_BROWSER_TEST_F(SetIconAPITest, Overview) {
ExtensionTestMessageListener ready("ready", false); ExtensionTestMessageListener ready("ready", false);
const Extension* extension = LoadExtension(ext_dir_.UnpackedPath()); const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const ExtensionAction* page_action = const ExtensionAction* page_action =
ExtensionActionManager::Get(browser()->profile())-> ExtensionActionManager::Get(browser()->profile())->
GetPageAction(*extension); GetPageAction(*extension);
......
...@@ -1547,6 +1547,9 @@ IN_PROC_BROWSER_TEST_F(NTPInterceptionWebRequestAPITest, ...@@ -1547,6 +1547,9 @@ IN_PROC_BROWSER_TEST_F(NTPInterceptionWebRequestAPITest,
LoadExtension(test_data_dir_.AppendASCII("extension")); LoadExtension(test_data_dir_.AppendASCII("extension"));
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
// Wait for webRequest listeners to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
// Have the extension listen for requests to |fake_ntp_script.js|. // Have the extension listen for requests to |fake_ntp_script.js|.
listener.Reply(https_test_server()->GetURL("/fake_ntp_script.js").spec()); listener.Reply(https_test_server()->GetURL("/fake_ntp_script.js").spec());
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#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/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/storage_partition.h"
#include "extensions/browser/browsertest_util.h" #include "extensions/browser/browsertest_util.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_urls.h" #include "extensions/common/extension_urls.h"
...@@ -60,7 +60,8 @@ class BackgroundXhrTest : public ExtensionBrowserTest { ...@@ -60,7 +60,8 @@ class BackgroundXhrTest : public ExtensionBrowserTest {
GURL test_url = net::AppendQueryParameter(extension->GetResourceURL(path), GURL test_url = net::AppendQueryParameter(extension->GetResourceURL(path),
"url", url.spec()); "url", url.spec());
ui_test_utils::NavigateToURL(browser(), test_url); ui_test_utils::NavigateToURL(browser(), test_url);
content::FlushNetworkServiceInstanceForTesting(); content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
constexpr char kSendXHRScript[] = R"( constexpr char kSendXHRScript[] = R"(
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('GET', '%s'); xhr.open('GET', '%s');
......
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