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 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.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_webrequest/webrequest_constants.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_rules_registry.h"
......@@ -186,6 +187,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest,
const Extension* extension = InstallExtensionWithUIAutoConfirm(
ext_dir.Pack(), 1 /*+1 installed extension*/, browser());
ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
std::string extension_id(extension->id());
ASSERT_TRUE(ready.WaitUntilSatisfied());
ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl));
......@@ -260,6 +264,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, MAYBE_NoTracesAfterUninstalling) {
const Extension* extension = InstallExtensionWithUIAutoConfirm(
ext_dir.Pack(), 1 /*+1 installed extension*/, browser());
ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
std::string extension_id(extension->id());
ASSERT_TRUE(ready.WaitUntilSatisfied());
ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl));
......@@ -270,6 +277,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, MAYBE_NoTracesAfterUninstalling) {
// 2. Uninstall the extension. Rules are gone and preferences should be empty.
UninstallExtension(extension_id);
// Wait for declarative rules to be removed.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
ui_test_utils::NavigateToURL(browser(), GURL(kArbitraryUrl));
EXPECT_NE(kTestTitle, GetTitle());
EXPECT_EQ(0u, NumberOfRegisteredRules(extension_id));
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_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 "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
......@@ -361,6 +362,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, ReusedActionInstance) {
ExtensionTestMessageListener ready("ready", false);
const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const ExtensionAction* page_action =
ExtensionActionManager::Get(browser()->profile())
->GetPageAction(*extension);
......@@ -605,6 +609,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const std::string extension_id = extension->id();
const ExtensionAction* page_action = ExtensionActionManager::Get(
browser()->profile())->GetPageAction(*extension);
......@@ -631,6 +638,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab));
ReloadExtension(extension_id); // Invalidates page_action and extension.
// Wait for declarative rules to be removed.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
EXPECT_EQ("test_rule",
ExecuteScriptInBackgroundPage(extension_id, kTestRule));
// TODO(jyasskin): Apply new rules to existing tabs, without waiting for a
......@@ -641,6 +651,9 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab));
UnloadExtension(extension_id);
// Wait for declarative rules to be removed.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
NavigateInRenderer(tab, GURL("http://test/"));
EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(0));
EXPECT_EQ(0u, extension_action_test_util::GetVisiblePageActionCount(tab));
......@@ -722,6 +735,9 @@ IN_PROC_BROWSER_TEST_P(ShowPageActionWithoutPageActionTest, Test) {
scoped_refptr<const Extension> extension =
loader.LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const char kScript[] =
"setRules([{\n"
......
......@@ -7,6 +7,7 @@
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/test_extension_dir.h"
......@@ -74,6 +75,9 @@ IN_PROC_BROWSER_TEST_F(SetIconAPITest, Overview) {
ExtensionTestMessageListener ready("ready", false);
const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
ASSERT_TRUE(extension);
// Wait for declarative rules to be set up.
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
const ExtensionAction* page_action =
ExtensionActionManager::Get(browser()->profile())->
GetPageAction(*extension);
......
......@@ -1547,6 +1547,9 @@ IN_PROC_BROWSER_TEST_F(NTPInterceptionWebRequestAPITest,
LoadExtension(test_data_dir_.AppendASCII("extension"));
ASSERT_TRUE(extension);
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|.
listener.Reply(https_test_server()->GetURL("/fake_ntp_script.js").spec());
......
......@@ -15,7 +15,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.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/common/extension.h"
#include "extensions/common/extension_urls.h"
......@@ -60,7 +60,8 @@ class BackgroundXhrTest : public ExtensionBrowserTest {
GURL test_url = net::AppendQueryParameter(extension->GetResourceURL(path),
"url", url.spec());
ui_test_utils::NavigateToURL(browser(), test_url);
content::FlushNetworkServiceInstanceForTesting();
content::BrowserContext::GetDefaultStoragePartition(profile())
->FlushNetworkInterfaceForTesting();
constexpr char kSendXHRScript[] = R"(
var xhr = new XMLHttpRequest();
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