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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// 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 <string>
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_helper.h"
#include "chrome/browser/extensions/page_action_controller.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_builder.h"
#include "chrome/common/extensions/value_builder.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
using content::BrowserThread;
namespace extensions {
namespace {
class PageActionControllerTest : public TabContentsTestHarness {
public:
PageActionControllerTest()
: ui_thread_(BrowserThread::UI, MessageLoop::current()) {
}
virtual void SetUp() {
TabContentsTestHarness::SetUp();
// Create an ExtensionService so the PageActionController can find its
// extensions.
CommandLine command_line(CommandLine::NO_PROGRAM);
extension_service_ =
static_cast<TestExtensionSystem*>(
ExtensionSystem::Get(tab_contents()->profile()))->
CreateExtensionService(
&command_line, FilePath(), false);
}
protected:
int tab_id() {
return tab_contents()->extension_tab_helper()->tab_id();
}
ExtensionService* extension_service_;
private:
content::TestBrowserThread ui_thread_;
};
TEST_F(PageActionControllerTest, NavigationClearsState) {
scoped_refptr<const Extension> extension =
ExtensionBuilder()
.SetManifest(DictionaryBuilder()
.Set("name", "Extension with page action")
.Set("version", "1.0.0")
.Set("manifest_version", 2)
.Set("permissions", ListBuilder()
.Append("tabs"))
.Set("page_action", DictionaryBuilder()
.Set("default_title", "Hello")))
.Build();
extension_service_->AddExtension(extension);
NavigateAndCommit(GURL("http://www.google.com"));
extension->page_action()->SetTitle(tab_id(), "Goodbye");
extension->page_action()->SetPopupUrl(
tab_id(), extension->GetResourceURL("popup.html"));
EXPECT_EQ("Goodbye", extension->page_action()->GetTitle(tab_id()));
EXPECT_EQ(extension->GetResourceURL("popup.html"),
extension->page_action()->GetPopupUrl(tab_id()));
// Should discard the settings, and go back to the defaults.
NavigateAndCommit(GURL("http://www.yahoo.com"));
EXPECT_EQ("Hello", extension->page_action()->GetTitle(tab_id()));
EXPECT_EQ(GURL(), extension->page_action()->GetPopupUrl(tab_id()));
};
} // namespace
} // namespace extensions
|