| Index: chrome/browser/extensions/api/declarative/rules_registry_service_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/declarative/rules_registry_service_unittest.cc b/chrome/browser/extensions/api/declarative/rules_registry_service_unittest.cc
|
| index d35dab4ae5feaf41dbd65486044e505efeb1bca6..33d18de5c1d21af66fc46879325e530f339fbc7d 100644
|
| --- a/chrome/browser/extensions/api/declarative/rules_registry_service_unittest.cc
|
| +++ b/chrome/browser/extensions/api/declarative/rules_registry_service_unittest.cc
|
| @@ -10,6 +10,7 @@
|
| #include "content/public/test/test_browser_thread.h"
|
| #include "extensions/browser/api/declarative/test_rules_registry.h"
|
| #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
|
| +#include "extensions/browser/guest_view/web_view/web_view_guest.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace {
|
| @@ -55,7 +56,9 @@ class RulesRegistryServiceTest : public testing::Test {
|
| };
|
|
|
| TEST_F(RulesRegistryServiceTest, TestConstructionAndMultiThreading) {
|
| - const RulesRegistry::WebViewKey key(0, 0);
|
| + RulesRegistryService registry_service(NULL);
|
| +
|
| + int key = RulesRegistryService::kDefultRulesRegistryID;
|
| TestRulesRegistry* ui_registry =
|
| new TestRulesRegistry(content::BrowserThread::UI, "ui", key);
|
|
|
| @@ -64,33 +67,34 @@ TEST_F(RulesRegistryServiceTest, TestConstructionAndMultiThreading) {
|
|
|
| // Test registration.
|
|
|
| - RulesRegistryService registry_service(NULL);
|
| registry_service.RegisterRulesRegistry(make_scoped_refptr(ui_registry));
|
| registry_service.RegisterRulesRegistry(make_scoped_refptr(io_registry));
|
|
|
| - EXPECT_TRUE(registry_service.GetRulesRegistry(key, "ui").get());
|
| - EXPECT_TRUE(registry_service.GetRulesRegistry(key, "io").get());
|
| - EXPECT_FALSE(registry_service.GetRulesRegistry(key, "foo").get());
|
| + EXPECT_TRUE(registry_service.GetRulesRegistry(key, false, "ui").get());
|
| + EXPECT_TRUE(registry_service.GetRulesRegistry(key, false, "io").get());
|
| + EXPECT_FALSE(registry_service.GetRulesRegistry(key, false, "foo").get());
|
|
|
| content::BrowserThread::PostTask(
|
| content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&InsertRule, registry_service.GetRulesRegistry(key, "ui"),
|
| + base::Bind(&InsertRule,
|
| + registry_service.GetRulesRegistry(key, false, "ui"),
|
| "ui_task"));
|
|
|
| content::BrowserThread::PostTask(
|
| - content::BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&InsertRule, registry_service.GetRulesRegistry(key, "io"),
|
| - "io_task"));
|
| + content::BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&InsertRule,
|
| + registry_service.GetRulesRegistry(key, false, "io"),
|
| + "io_task"));
|
|
|
| content::BrowserThread::PostTask(
|
| - content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&VerifyNumberOfRules,
|
| - registry_service.GetRulesRegistry(key, "ui"), 1));
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&VerifyNumberOfRules,
|
| + registry_service.GetRulesRegistry(key, false, "ui"), 1));
|
|
|
| content::BrowserThread::PostTask(
|
| - content::BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&VerifyNumberOfRules,
|
| - registry_service.GetRulesRegistry(key, "io"), 1));
|
| + content::BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&VerifyNumberOfRules,
|
| + registry_service.GetRulesRegistry(key, false, "io"), 1));
|
|
|
| message_loop_.RunUntilIdle();
|
|
|
| @@ -99,14 +103,14 @@ TEST_F(RulesRegistryServiceTest, TestConstructionAndMultiThreading) {
|
| registry_service.SimulateExtensionUninstalled(kExtensionId);
|
|
|
| content::BrowserThread::PostTask(
|
| - content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&VerifyNumberOfRules,
|
| - registry_service.GetRulesRegistry(key, "ui"), 0));
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&VerifyNumberOfRules,
|
| + registry_service.GetRulesRegistry(key, false, "ui"), 0));
|
|
|
| content::BrowserThread::PostTask(
|
| - content::BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&VerifyNumberOfRules,
|
| - registry_service.GetRulesRegistry(key, "io"), 0));
|
| + content::BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&VerifyNumberOfRules,
|
| + registry_service.GetRulesRegistry(key, false, "io"), 0));
|
|
|
| message_loop_.RunUntilIdle();
|
| }
|
| @@ -115,48 +119,59 @@ TEST_F(RulesRegistryServiceTest, TestConstructionAndMultiThreading) {
|
| // intended. This test ensures that removing registries associated with one
|
| // Webview embedder process does not remove registries associated with the
|
| // other.
|
| -TEST_F(RulesRegistryServiceTest, TestWebViewKey) {
|
| +TEST_F(RulesRegistryServiceTest, TestWebViewRulesRegistryIDsAreGone) {
|
| const int kEmbedderProcessID1 = 1;
|
| const int kEmbedderProcessID2 = 2;
|
| const int kWebViewInstanceID = 1;
|
|
|
| - const RulesRegistry::WebViewKey key1(kEmbedderProcessID1, kWebViewInstanceID);
|
| - const RulesRegistry::WebViewKey key2(kEmbedderProcessID2, kWebViewInstanceID);
|
| -
|
| - TestRulesRegistry* ui_registry_key1 =
|
| - new TestRulesRegistry(content::BrowserThread::UI, "ui", key1);
|
| - TestRulesRegistry* ui_registry_key2 =
|
| - new TestRulesRegistry(content::BrowserThread::UI, "ui", key2);
|
| -
|
| RulesRegistryService registry_service(NULL);
|
| + int rules_registry_id1 = 0;
|
| + WebViewGuest::GenerateRulesRegistryID(kEmbedderProcessID1, kWebViewInstanceID,
|
| + ®istry_service, &rules_registry_id1);
|
| + int rules_registry_id2 = 0;
|
| + WebViewGuest::GenerateRulesRegistryID(kEmbedderProcessID2, kWebViewInstanceID,
|
| + ®istry_service, &rules_registry_id2);
|
| +
|
| + TestRulesRegistry* ui_registry_key1 = new TestRulesRegistry(
|
| + content::BrowserThread::UI, "ui", rules_registry_id1);
|
| + TestRulesRegistry* ui_registry_key2 = new TestRulesRegistry(
|
| + content::BrowserThread::UI, "ui", rules_registry_id2);
|
| +
|
| registry_service.RegisterRulesRegistry(make_scoped_refptr(ui_registry_key1));
|
| registry_service.RegisterRulesRegistry(make_scoped_refptr(ui_registry_key2));
|
|
|
| content::BrowserThread::PostTask(
|
| content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&InsertRule, registry_service.GetRulesRegistry(key1, "ui"),
|
| + base::Bind(&InsertRule, registry_service.GetRulesRegistry(
|
| + rules_registry_id1, true, "ui"),
|
| "ui_task"));
|
| content::BrowserThread::PostTask(
|
| content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&InsertRule, registry_service.GetRulesRegistry(key2, "ui"),
|
| + base::Bind(&InsertRule, registry_service.GetRulesRegistry(
|
| + rules_registry_id2, true, "ui"),
|
| "ui_task"));
|
| message_loop_.RunUntilIdle();
|
|
|
| registry_service.RemoveWebViewRulesRegistries(kEmbedderProcessID1);
|
| - EXPECT_FALSE(registry_service.GetRulesRegistry(key1, "ui").get());
|
| - EXPECT_TRUE(registry_service.GetRulesRegistry(key2, "ui").get());
|
| + EXPECT_FALSE(
|
| + registry_service.GetRulesRegistry(rules_registry_id1, true, "ui").get());
|
| + EXPECT_TRUE(
|
| + registry_service.GetRulesRegistry(rules_registry_id2, true, "ui").get());
|
| }
|
|
|
| TEST_F(RulesRegistryServiceTest, TestWebViewWebRequestRegistryHasNoCache) {
|
| const int kEmbedderProcessID = 1;
|
| const int kWebViewInstanceID = 1;
|
| - const RulesRegistry::WebViewKey key(kEmbedderProcessID, kWebViewInstanceID);
|
| TestingProfile profile;
|
| RulesRegistryService registry_service(&profile);
|
| + int rules_registry_id = 0;
|
| + WebViewGuest::GenerateRulesRegistryID(kEmbedderProcessID, kWebViewInstanceID,
|
| + ®istry_service, &rules_registry_id);
|
| +
|
| RulesRegistry* registry =
|
| registry_service.GetRulesRegistry(
|
| - key,
|
| - declarative_webrequest_constants::kOnRequest).get();
|
| + rules_registry_id, true,
|
| + declarative_webrequest_constants::kOnRequest).get();
|
| EXPECT_TRUE(registry);
|
| EXPECT_FALSE(registry->rules_cache_delegate_for_testing());
|
| }
|
|
|