blob: 3e56f452b6636ee05bc56d555f4f4a7995e599f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h"
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_thread.h"
using extensions::RulesRegistry;
using extensions::RulesRegistryService;
using extensions::WebRequestRulesRegistry;
class DeclarativeApiTest : public ExtensionApiTest {
public:
DeclarativeApiTest() {}
virtual ~DeclarativeApiTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
}
};
IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) {
ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_;
// Check that unloading the page has removed all rules.
std::string extension_id = GetSingleLoadedExtension()->id();
UnloadExtension(extension_id);
// UnloadExtension posts a task to the owner thread of the extension
// to process this unloading. The next task to retrive all rules
// is therefore processed after the UnloadExtension task has been executed.
RulesRegistryService* rules_registry_service =
ExtensionSystemFactory::GetForProfile(browser()->profile())->
rules_registry_service();
scoped_refptr<RulesRegistry> rules_registry =
rules_registry_service->GetRulesRegistry(
extensions::declarative_webrequest_constants::kOnRequest);
std::vector<linked_ptr<RulesRegistry::Rule> > known_rules;
content::BrowserThread::PostTask(
rules_registry->GetOwnerThread(),
FROM_HERE,
base::Bind(base::IgnoreResult(&RulesRegistry::GetAllRules),
rules_registry, extension_id, &known_rules));
ui_test_utils::RunAllPendingInMessageLoop(rules_registry->GetOwnerThread());
EXPECT_TRUE(known_rules.empty());
}
|