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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// Copyright (c) 2011 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/command_line.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/render_view_context_menu.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/models/menu_model.h"
#include "webkit/glue/context_menu.h"
namespace {
// Non-abstract RenderViewContextMenu class.
class PlatformAppContextMenu : public RenderViewContextMenu {
public:
PlatformAppContextMenu(TabContents* tab_contents,
const ContextMenuParams& params)
: RenderViewContextMenu(tab_contents, params) {}
protected:
// These two functions implement pure virtual methods of
// RenderViewContextMenu.
virtual bool GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
return false;
}
virtual void PlatformInit() {}
};
} // namespace
class PlatformAppBrowserTest : public ExtensionBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) {
ExtensionBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnablePlatformApps);
}
void LoadAndLaunchPlatformApp(const char* name) {
web_app::SetDisableShortcutCreationForTests(true);
EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps").
AppendASCII(name)));
ExtensionService* service = browser()->profile()->GetExtensionService();
const Extension* extension = service->GetExtensionById(
last_loaded_extension_id_, false);
EXPECT_TRUE(extension);
size_t browser_count = BrowserList::size();
Browser::OpenApplication(
browser()->profile(),
extension,
extension_misc::LAUNCH_SHELL,
GURL(),
NEW_WINDOW);
// Now we have a new browser instance.
EXPECT_EQ(browser_count + 1, BrowserList::size());
}
};
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenAppInShellContainer) {
// Start with one browser, new platform app will create another.
ASSERT_EQ(1u, BrowserList::size());
LoadAndLaunchPlatformApp("empty");
// The launch should have created a new browser, so there should be 2 now.
ASSERT_EQ(2u, BrowserList::size());
// The new browser is the last one.
BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end());
Browser* new_browser = *(reverse_iterator++);
ASSERT_TRUE(new_browser);
ASSERT_TRUE(new_browser != browser());
// Expect an app in a shell window.
EXPECT_TRUE(new_browser->is_app());
EXPECT_TRUE(new_browser->is_type_shell());
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
// Start with one browser, new platform app will create another.
ASSERT_EQ(1u, BrowserList::size());
LoadAndLaunchPlatformApp("empty");
// The launch should have created a new browser, so there should be 2 now.
ASSERT_EQ(2u, BrowserList::size());
// The new browser is the last one.
BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end());
Browser* new_browser = *(reverse_iterator++);
ASSERT_TRUE(new_browser);
ASSERT_TRUE(new_browser != browser());
// The empty app doesn't add any context menu items, so its menu should
// be empty.
TabContents* tab_contents = new_browser->GetSelectedTabContents();
WebKit::WebContextMenuData data;
ContextMenuParams params(data);
PlatformAppContextMenu* menu = new PlatformAppContextMenu(tab_contents,
params);
menu->Init();
ASSERT_FALSE(menu->menu_model().GetItemCount());
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
// Start with one browser, new platform app will create another.
ASSERT_EQ(1u, BrowserList::size());
ExtensionTestMessageListener listener1("created item", false);
LoadAndLaunchPlatformApp("context_menu");
// Wait for the extension to tell us it's created an item.
ASSERT_TRUE(listener1.WaitUntilSatisfied());
// The launch should have created a new browser, so there should be 2 now.
ASSERT_EQ(2u, BrowserList::size());
// The new browser is the last one.
BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end());
Browser* new_browser = *(reverse_iterator++);
ASSERT_TRUE(new_browser);
ASSERT_TRUE(new_browser != browser());
// The context_menu app has one context menu item. This is all that should
// be in the menu, there should be no seperator.
TabContents* tab_contents = new_browser->GetSelectedTabContents();
WebKit::WebContextMenuData data;
ContextMenuParams params(data);
PlatformAppContextMenu* menu = new PlatformAppContextMenu(tab_contents,
params);
menu->Init();
ASSERT_EQ(1, menu->menu_model().GetItemCount());
}
|