Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/extensions/extension_webnavigation_apitest.cc

Issue 9959097: Move webNavigation extension api into a separate directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/app/chrome_command_ids.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_webnavigation_api.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/tab_contents/render_view_context_menu.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/context_menu_params.h"
18 #include "net/base/mock_host_resolver.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
21
22 using content::WebContents;
23
24 #if defined(OS_WIN)
25 // http://crbug.com/118478
26 #define MAYBE_WebNavigationIFrame DISABLED_WebNavigationIFrame
27 #define MAYBE_WebNavigationFailures DISABLED_WebNavigationFailures
28 #define MAYBE_WebNavigationForwardBack DISABLED_WebNavigationForwardBack
29 #define MAYBE_WebNavigationClientRedirect DISABLED_WebNavigationClientRedirect
30 #define MAYBE_WebNavigationGetFrame DISABLED_WebNavigationGetFrame
31 #define MAYBE_WebNavigationSimpleLoad DISABLED_WebNavigationSimpleLoad
32 #define MAYBE_WebNavigationReferenceFragment \
33 DISABLED_WebNavigationReferenceFragment
34 #define MAYBE_WebNavigationOpenTab DISABLED_WebNavigationOpenTab
35 #else
36 #define MAYBE_WebNavigationIFrame WebNavigationIFrame
37 #define MAYBE_WebNavigationFailures WebNavigationFailures
38 #define MAYBE_WebNavigationForwardBack WebNavigationForwardBack
39 #define MAYBE_WebNavigationClientRedirect WebNavigationClientRedirect
40 #define MAYBE_WebNavigationGetFrame WebNavigationGetFrame
41 #define MAYBE_WebNavigationSimpleLoad WebNavigationSimpleLoad
42 #define MAYBE_WebNavigationReferenceFragment WebNavigationReferenceFragment
43 #define MAYBE_WebNavigationOpenTab WebNavigationOpenTab
44 #endif
45
46 namespace {
47
48 class TestRenderViewContextMenu : public RenderViewContextMenu {
49 public:
50 TestRenderViewContextMenu(WebContents* web_contents,
51 const content::ContextMenuParams& params)
52 : RenderViewContextMenu(web_contents, params) {
53 }
54 virtual ~TestRenderViewContextMenu() {}
55
56 private:
57 virtual void PlatformInit() {}
58 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) {
59 return false;
60 }
61
62 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu);
63 };
64
65 } // namespace
66
67 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigation) {
68 FrameNavigationState::set_allow_extension_scheme(true);
69
70 CommandLine::ForCurrentProcess()->AppendSwitch(
71 switches::kAllowLegacyExtensionManifests);
72
73 ASSERT_TRUE(
74 RunExtensionSubtest("webnavigation", "test_api.html")) << message_;
75 }
76
77 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationGetFrame) {
78 FrameNavigationState::set_allow_extension_scheme(true);
79
80 CommandLine::ForCurrentProcess()->AppendSwitch(
81 switches::kAllowLegacyExtensionManifests);
82
83 ASSERT_TRUE(
84 RunExtensionSubtest("webnavigation", "test_getFrame.html")) << message_;
85 }
86
87 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationClientRedirect) {
88 FrameNavigationState::set_allow_extension_scheme(true);
89
90 CommandLine::ForCurrentProcess()->AppendSwitch(
91 switches::kAllowLegacyExtensionManifests);
92
93 ASSERT_TRUE(
94 RunExtensionSubtest("webnavigation", "test_clientRedirect.html"))
95 << message_;
96 }
97
98 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationServerRedirect) {
99 FrameNavigationState::set_allow_extension_scheme(true);
100 host_resolver()->AddRule("*", "127.0.0.1");
101 ASSERT_TRUE(StartTestServer());
102
103 CommandLine::ForCurrentProcess()->AppendSwitch(
104 switches::kAllowLegacyExtensionManifests);
105
106 ASSERT_TRUE(
107 RunExtensionSubtest("webnavigation", "test_serverRedirect.html"))
108 << message_;
109 }
110
111 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationForwardBack) {
112 FrameNavigationState::set_allow_extension_scheme(true);
113
114 CommandLine::ForCurrentProcess()->AppendSwitch(
115 switches::kAllowLegacyExtensionManifests);
116
117 ASSERT_TRUE(
118 RunExtensionSubtest("webnavigation", "test_forwardBack.html"))
119 << message_;
120 }
121
122 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationIFrame) {
123 FrameNavigationState::set_allow_extension_scheme(true);
124
125 CommandLine::ForCurrentProcess()->AppendSwitch(
126 switches::kAllowLegacyExtensionManifests);
127
128 ASSERT_TRUE(
129 RunExtensionSubtest("webnavigation", "test_iframe.html")) << message_;
130 }
131
132 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationOpenTab) {
133 FrameNavigationState::set_allow_extension_scheme(true);
134
135 CommandLine::ForCurrentProcess()->AppendSwitch(
136 switches::kAllowLegacyExtensionManifests);
137
138 ASSERT_TRUE(
139 RunExtensionSubtest("webnavigation", "test_openTab.html")) << message_;
140 }
141
142 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationReferenceFragment) {
143 FrameNavigationState::set_allow_extension_scheme(true);
144
145 CommandLine::ForCurrentProcess()->AppendSwitch(
146 switches::kAllowLegacyExtensionManifests);
147
148 ASSERT_TRUE(
149 RunExtensionSubtest("webnavigation", "test_referenceFragment.html"))
150 << message_;
151 }
152
153 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationSimpleLoad) {
154 FrameNavigationState::set_allow_extension_scheme(true);
155
156 CommandLine::ForCurrentProcess()->AppendSwitch(
157 switches::kAllowLegacyExtensionManifests);
158
159 ASSERT_TRUE(
160 RunExtensionSubtest("webnavigation", "test_simpleLoad.html")) << message_;
161 }
162
163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationFailures) {
164 FrameNavigationState::set_allow_extension_scheme(true);
165
166 CommandLine::ForCurrentProcess()->AppendSwitch(
167 switches::kAllowLegacyExtensionManifests);
168
169 ASSERT_TRUE(
170 RunExtensionSubtest("webnavigation", "test_failures.html")) << message_;
171 }
172
173 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationUserAction) {
174 FrameNavigationState::set_allow_extension_scheme(true);
175
176 CommandLine::ForCurrentProcess()->AppendSwitch(
177 switches::kAllowLegacyExtensionManifests);
178
179 // Wait for the extension to set itself up and return control to us.
180 ASSERT_TRUE(
181 RunExtensionSubtest("webnavigation", "test_userAction.html")) << message_;
182
183 WebContents* tab = browser()->GetSelectedWebContents();
184 ui_test_utils::WaitForLoadStop(tab);
185
186 ResultCatcher catcher;
187
188 ExtensionService* service = browser()->profile()->GetExtensionService();
189 const Extension* extension =
190 service->GetExtensionById(last_loaded_extension_id_, false);
191 GURL url = extension->GetResourceURL("userAction/a.html");
192
193 ui_test_utils::NavigateToURL(browser(), url);
194
195 // This corresponds to "Open link in new tab".
196 content::ContextMenuParams params;
197 params.is_editable = false;
198 params.media_type = WebKit::WebContextMenuData::MediaTypeNone;
199 params.page_url = url;
200 params.frame_id =
201 ExtensionWebNavigationTabObserver::Get(tab)->
202 frame_navigation_state().GetMainFrameID();
203 params.link_url = extension->GetResourceURL("userAction/b.html");
204
205 TestRenderViewContextMenu menu(tab, params);
206 menu.Init();
207 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);
208
209 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
210 }
211
212 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationRequestOpenTab) {
213 FrameNavigationState::set_allow_extension_scheme(true);
214
215 CommandLine::ForCurrentProcess()->AppendSwitch(
216 switches::kAllowLegacyExtensionManifests);
217
218 // Wait for the extension to set itself up and return control to us.
219 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_requestOpenTab.html"))
220 << message_;
221
222 WebContents* tab = browser()->GetSelectedWebContents();
223 ui_test_utils::WaitForLoadStop(tab);
224
225 ResultCatcher catcher;
226
227 ExtensionService* service = browser()->profile()->GetExtensionService();
228 const Extension* extension =
229 service->GetExtensionById(last_loaded_extension_id_, false);
230 GURL url = extension->GetResourceURL("requestOpenTab/a.html");
231
232 ui_test_utils::NavigateToURL(browser(), url);
233
234 // There's a link on a.html. Middle-click on it to open it in a new tab.
235 WebKit::WebMouseEvent mouse_event;
236 mouse_event.type = WebKit::WebInputEvent::MouseDown;
237 mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle;
238 mouse_event.x = 7;
239 mouse_event.y = 7;
240 mouse_event.clickCount = 1;
241 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
242 mouse_event.type = WebKit::WebInputEvent::MouseUp;
243 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
244
245 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
246 }
247
248 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationTargetBlank) {
249 FrameNavigationState::set_allow_extension_scheme(true);
250 ASSERT_TRUE(StartTestServer());
251
252 CommandLine::ForCurrentProcess()->AppendSwitch(
253 switches::kAllowLegacyExtensionManifests);
254
255 // Wait for the extension to set itself up and return control to us.
256 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_targetBlank.html"))
257 << message_;
258
259 WebContents* tab = browser()->GetSelectedWebContents();
260 ui_test_utils::WaitForLoadStop(tab);
261
262 ResultCatcher catcher;
263
264 GURL url = test_server()->GetURL(
265 "files/extensions/api_test/webnavigation/targetBlank/a.html");
266
267 browser::NavigateParams params(browser(), url, content::PAGE_TRANSITION_LINK);
268 ui_test_utils::NavigateToURL(&params);
269
270 // There's a link with target=_blank on a.html. Click on it to open it in a
271 // new tab.
272 WebKit::WebMouseEvent mouse_event;
273 mouse_event.type = WebKit::WebInputEvent::MouseDown;
274 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
275 mouse_event.x = 7;
276 mouse_event.y = 7;
277 mouse_event.clickCount = 1;
278 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
279 mouse_event.type = WebKit::WebInputEvent::MouseUp;
280 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
281
282 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
283 }
284
285 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationTargetBlankIncognito) {
286 FrameNavigationState::set_allow_extension_scheme(true);
287 ASSERT_TRUE(StartTestServer());
288
289 CommandLine::ForCurrentProcess()->AppendSwitch(
290 switches::kAllowLegacyExtensionManifests);
291
292 // Wait for the extension to set itself up and return control to us.
293 ASSERT_TRUE(RunExtensionSubtest(
294 "webnavigation", "test_targetBlank.html",
295 ExtensionApiTest::kFlagEnableIncognito)) << message_;
296
297 ResultCatcher catcher;
298
299 GURL url = test_server()->GetURL(
300 "files/extensions/api_test/webnavigation/targetBlank/a.html");
301
302 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), url);
303 WebContents* tab = BrowserList::FindTabbedBrowser(
304 browser()->profile()->GetOffTheRecordProfile(), false)->
305 GetSelectedWebContents();
306
307 // There's a link with target=_blank on a.html. Click on it to open it in a
308 // new tab.
309 WebKit::WebMouseEvent mouse_event;
310 mouse_event.type = WebKit::WebInputEvent::MouseDown;
311 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
312 mouse_event.x = 7;
313 mouse_event.y = 7;
314 mouse_event.clickCount = 1;
315 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
316 mouse_event.type = WebKit::WebInputEvent::MouseUp;
317 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
318
319 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698