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

Side by Side Diff: chrome_frame/test/navigation_test.cc

Issue 2822016: [chrome_frame] Refactor/merge IE no interference tests with other mock event ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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
« no previous file with comments | « chrome_frame/test/mock_ie_event_sink_test.cc ('k') | chrome_frame/test/no_interference_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 <string>
6
7 #include "base/scoped_comptr_win.h"
8 #include "base/win_util.h"
9 #include "chrome_frame/test/chrome_frame_test_utils.h"
10 #include "chrome_frame/test/mock_ie_event_sink_actions.h"
11 #include "chrome_frame/test/mock_ie_event_sink_test.h"
12
13 // Needed for CreateFunctor.
14 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
15 #include "testing/gmock_mutant.h"
16
17 using testing::_;
18 using testing::InSequence;
19 using testing::StrEq;
20
21 namespace chrome_frame_test {
22
23 const wchar_t tab_enter_keys[] = { VK_TAB, VK_RETURN, 0 };
24
25 // Test fixture for navigation-related tests. Each test is run thrice: IE, CF
26 // with meta tag invocation, and CF with http header invocation. This is
27 // accomplished by using gTest's parameterized test.
28 class FullTabNavigationTest
29 : public MockIEEventSinkTest, public testing::TestWithParam<CFInvocation> {
30 public:
31 FullTabNavigationTest() {}
32 };
33
34 // Instantiate each test case. Instead of doing in one statement, it is split
35 // into three so gTest prints nicer names.
36 INSTANTIATE_TEST_CASE_P(IE, FullTabNavigationTest, testing::Values(
37 CFInvocation(CFInvocation::NONE)));
38 INSTANTIATE_TEST_CASE_P(MetaTag, FullTabNavigationTest, testing::Values(
39 CFInvocation(CFInvocation::META_TAG)));
40 INSTANTIATE_TEST_CASE_P(HttpHeader, FullTabNavigationTest, testing::Values(
41 CFInvocation(CFInvocation::HTTP_HEADER)));
42
43 // This tests navigation to a typed URL.
44 TEST_P(FullTabNavigationTest, FLAKY_TypeUrl) {
45 ie_mock_.ExpectNavigation(IN_IE, GetSimplePageUrl());
46 server_mock_.ExpectAndServeRequest(CFInvocation::None(), GetSimplePageUrl());
47 EXPECT_CALL(ie_mock_, OnLoad(IN_IE, StrEq(GetSimplePageUrl())))
48 .WillOnce(testing::DoAll(
49 SetFocusToRenderer(&ie_mock_),
50 TypeUrlInAddressBar(&loop_, GetAnchorPageUrl(0), 2000)));
51
52 bool in_cf = GetParam().invokes_cf();
53 ie_mock_.ExpectNavigation(in_cf, GetAnchorPageUrl(0));
54 server_mock_.ExpectAndServeRequest(GetParam(), GetAnchorPageUrl(0));
55 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(0))))
56 .WillOnce(CloseBrowserMock(&ie_mock_));
57
58 LaunchIEAndNavigate(GetSimplePageUrl());
59 }
60
61 // This tests navigation to a typed URL containing an fragment.
62 TEST_P(FullTabNavigationTest, FLAKY_TypeAnchorUrl) {
63 if (IsIBrowserServicePatchEnabled()) {
64 LOG(ERROR) << "Not running test. IBrowserServicePatch is in place.";
65 return;
66 }
67
68 ie_mock_.ExpectNavigation(IN_IE, GetSimplePageUrl());
69 server_mock_.ExpectAndServeRequest(CFInvocation::None(), GetSimplePageUrl());
70 EXPECT_CALL(ie_mock_, OnLoad(IN_IE, StrEq(GetSimplePageUrl())))
71 .WillOnce(testing::DoAll(
72 SetFocusToRenderer(&ie_mock_),
73 TypeUrlInAddressBar(&loop_, GetAnchorPageUrl(1), 2000)));
74
75 bool in_cf = GetParam().invokes_cf();
76 ie_mock_.ExpectNavigation(in_cf, GetAnchorPageUrl(1));
77 server_mock_.ExpectAndServeRequest(GetParam(), GetAnchorPageUrl(1));
78 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(1))))
79 .WillOnce(CloseBrowserMock(&ie_mock_));
80
81 LaunchIEAndNavigate(GetSimplePageUrl());
82 }
83
84 // Tests refreshing when a cached copy is available.
85 TEST_P(FullTabNavigationTest, FLAKY_RefreshWithCachedCopy) {
86 if (GetInstalledIEVersion() == IE_7) {
87 LOG(ERROR) << "Test disabled for this configuration.";
88 return;
89 }
90 bool in_cf = GetParam().invokes_cf();
91 ie_mock_.ExpectAnyNavigations();
92 InSequence expect_in_scope_for_sequence;
93
94 testing::Cardinality initial_req_cardinality = testing::Exactly(1);
95 // TODO(kkania): Remove this allowance for double request on meta tag when no
96 // longer necessary.
97 if (GetParam().type() == CFInvocation::META_TAG)
98 initial_req_cardinality = testing::Between(1, 2);
99 EXPECT_CALL(server_mock_, Get(_, UrlPathEq(GetSimplePageUrl()), _))
100 .Times(initial_req_cardinality)
101 .WillRepeatedly(SendAllowCacheResponse(&server_mock_, GetParam()));
102 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetSimplePageUrl())))
103 .WillOnce(testing::DoAll(
104 SetFocusToRenderer(&ie_mock_),
105 DelayRefresh(&ie_mock_, &loop_, 0)));
106
107 if (in_cf) {
108 // For some reason IE7 requests the resource again.
109 if (GetInstalledIEVersion() == IE_7) {
110 server_mock_.ExpectAndServeRequest(GetParam(), GetSimplePageUrl());
111 }
112 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetSimplePageUrl())))
113 .WillOnce(testing::DoAll(
114 SetFocusToRenderer(&ie_mock_),
115 CloseBrowserMock(&ie_mock_)));
116 } else {
117 // For some reason IE still requests the resource again, but does not
118 // trigger another load.
119 EXPECT_CALL(server_mock_, Get(_, UrlPathEq(GetSimplePageUrl()), _))
120 .WillOnce(CloseBrowserMock(&ie_mock_));
121 }
122
123 LaunchIEAndNavigate(GetSimplePageUrl());
124 }
125
126 // Test that multiple back and forward requests work.
127 TEST_P(FullTabNavigationTest, FLAKY_MultipleBackForward) {
128 std::wstring page1 = GetSimplePageUrl();
129 std::wstring page2 = GetLinkPageUrl();
130 std::wstring page3 = GetAnchorPageUrl(0);
131 bool in_cf = GetParam().invokes_cf();
132 server_mock_.ExpectAndServeAnyRequests(GetParam());
133 InSequence expect_in_sequence_for_scope;
134
135 // Navigate to url 2 after the previous navigation is complete.
136 ie_mock_.ExpectNavigation(in_cf, page1);
137 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page1)))
138 .WillOnce(testing::DoAll(
139 VerifyAddressBarUrl(&ie_mock_),
140 Navigate(&ie_mock_, page2)));
141
142 // Navigate to url 3 after the previous navigation is complete.
143 ie_mock_.ExpectNavigation(in_cf, page2);
144 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page2)))
145 .WillOnce(testing::DoAll(
146 VerifyAddressBarUrl(&ie_mock_),
147 Navigate(&ie_mock_, page3)));
148
149 // We have reached url 3 and have two back entries for url 1 & 2.
150 // Go back to url 2 now.
151 ie_mock_.ExpectNavigation(in_cf, page3);
152 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page3)))
153 .WillOnce(testing::DoAll(
154 VerifyAddressBarUrl(&ie_mock_),
155 DelayGoBack(&ie_mock_, &loop_, 0)));
156
157 // We have reached url 2 and have 1 back & 1 forward entries for url 1 & 3.
158 // Go back to url 1 now.
159 ie_mock_.ExpectNavigation(in_cf, page2);
160 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page2)))
161 .WillOnce(testing::DoAll(
162 VerifyAddressBarUrl(&ie_mock_),
163 DelayGoBack(&ie_mock_, &loop_, 0)));
164
165 // We have reached url 1 and have 0 back & 2 forward entries for url 2 & 3.
166 // Go forward to url 2 now.
167 ie_mock_.ExpectNavigation(in_cf, page1);
168 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page1)))
169 .WillOnce(testing::DoAll(
170 VerifyAddressBarUrl(&ie_mock_),
171 DelayGoForward(&ie_mock_, &loop_, 0)));
172
173 // We have reached url 2 and have 1 back & 1 forward entries for url 1 & 3.
174 // Go forward to url 3 now.
175 ie_mock_.ExpectNavigation(in_cf, page2);
176 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page2)))
177 .WillOnce(testing::DoAll(
178 VerifyAddressBarUrl(&ie_mock_),
179 DelayGoForward(&ie_mock_, &loop_, 0)));
180
181 // We have reached url 2 and have 1 back & 1 forward entries for url 1 & 3.
182 ie_mock_.ExpectNavigation(in_cf, page3);
183 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page3)))
184 .WillOnce(testing::DoAll(
185 VerifyAddressBarUrl(&ie_mock_),
186 CloseBrowserMock(&ie_mock_)));
187
188 LaunchIEAndNavigate(page1);
189 }
190
191 // Test multiple back and forward operations among urls with anchors.
192 // Marking this test FLAKY as it fails at times on the buildbot.
193 // http://code.google.com/p/chromium/issues/detail?id=26549
194 TEST_P(FullTabNavigationTest, FLAKY_BackForwardAnchor) {
195 bool in_cf = GetParam().invokes_cf();
196 if (!in_cf) {
197 LOG(ERROR) << "Test not yet implemented.";
198 return;
199 }
200 server_mock_.ExpectAndServeAnyRequests(GetParam());
201 InSequence expect_in_sequence_for_scope;
202
203 // Navigate to anchor 1:
204 // - First set focus to chrome renderer window
205 // Call WebBrowserEventSink::SetFocusToRenderer only once
206 // in the beginning. Calling it again will change focus from the
207 // current location to an element near the simulated mouse click.
208 // - Then send keyboard input of TAB + ENTER to cause navigation.
209 // It's better to send input as PostDelayedTask since the Activex
210 // message loop_ on the other side might be blocked when we get
211 // called in Onload.
212 // Back/Forward state at this point:
213 // Back: 0
214 // Forward: 0
215 ie_mock_.ExpectNavigation(in_cf, GetAnchorPageUrl(0));
216 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(0))))
217 .WillOnce(testing::DoAll(
218 SetFocusToRenderer(&ie_mock_),
219 DelaySendString(&loop_, 500, tab_enter_keys)));
220
221 // Navigate to anchor 2 after the previous navigation is complete
222 // Back/Forward state at this point:
223 // Back: 1 (kAnchorUrl)
224 // Forward: 0
225 ie_mock_.ExpectInPageNavigation(in_cf, GetAnchorPageUrl(1));
226 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(1))))
227 .WillOnce(testing::DoAll(
228 VerifyAddressBarUrl(&ie_mock_),
229 DelaySendString(&loop_, 500, tab_enter_keys)));
230
231 // Navigate to anchor 3 after the previous navigation is complete
232 // Back/Forward state at this point:
233 // Back: 2 (kAnchorUrl, kAnchor1Url)
234 // Forward: 0
235 ie_mock_.ExpectInPageNavigation(in_cf, GetAnchorPageUrl(2));
236 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(2))))
237 .WillOnce(testing::DoAll(
238 VerifyAddressBarUrl(&ie_mock_),
239 DelaySendString(&loop_, 500, tab_enter_keys)));
240
241 // We will reach anchor 3 once the navigation is complete,
242 // then go back to anchor 2
243 // Back/Forward state at this point:
244 // Back: 3 (kAnchorUrl, kAnchor1Url, kAnchor2Url)
245 // Forward: 0
246 ie_mock_.ExpectInPageNavigation(in_cf, GetAnchorPageUrl(3));
247 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(3))))
248 .WillOnce(testing::DoAll(
249 VerifyAddressBarUrl(&ie_mock_),
250 DelayGoBack(&ie_mock_, &loop_, 0)));
251
252 // We will reach anchor 2 once the navigation is complete,
253 // then go back to anchor 1
254 // Back/Forward state at this point:
255 // Back: 3 (kAnchorUrl, kAnchor1Url, kAnchor2Url)
256 // Forward: 1 (kAnchor3Url)
257 ie_mock_.ExpectNavigation(in_cf, GetAnchorPageUrl(2));
258 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(2))))
259 .WillOnce(testing::DoAll(
260 VerifyAddressBarUrl(&ie_mock_),
261 DelayGoBack(&ie_mock_, &loop_, 0)));
262
263 // We will reach anchor 1 once the navigation is complete,
264 // now go forward to anchor 2
265 // Back/Forward state at this point:
266 // Back: 2 (kAnchorUrl, kAnchor1Url)
267 // Forward: 2 (kAnchor2Url, kAnchor3Url)
268 ie_mock_.ExpectNavigation(in_cf, GetAnchorPageUrl(1));
269 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(1))))
270 .WillOnce(testing::DoAll(
271 VerifyAddressBarUrl(&ie_mock_),
272 DelayGoForward(&ie_mock_, &loop_, 0)));
273
274 // We have reached anchor 2, go forward to anchor 3 again
275 // Back/Forward state at this point:
276 // Back: 3 (kAnchorUrl, kAnchor1Url, kAnchor2Url)
277 // Forward: 1 (kAnchor3Url)
278 ie_mock_.ExpectNavigation(in_cf, GetAnchorPageUrl(2));
279 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(2))))
280 .WillOnce(testing::DoAll(
281 VerifyAddressBarUrl(&ie_mock_),
282 DelayGoForward(&ie_mock_, &loop_, 0)));
283
284 // We have gone a few steps back and forward, this should be enough for now.
285 ie_mock_.ExpectNavigation(in_cf, GetAnchorPageUrl(3));
286 EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(GetAnchorPageUrl(3))))
287 .WillOnce(CloseBrowserMock(&ie_mock_));
288
289 LaunchIEAndNavigate(GetAnchorPageUrl(0));
290 }
291
292 // Test that a user cannot navigate to a restricted site and that the security
293 // dialog appears.
294 TEST_P(FullTabNavigationTest, FLAKY_RestrictedSite) {
295 if (!GetParam().invokes_cf() || GetInstalledIEVersion() == IE_8) {
296 // Test has been disabled on IE8 bot because it hangs at times.
297 // http://crbug.com/47596
298 LOG(ERROR) << "Test disabled for this configuration.";
299 return;
300 }
301 if (IsIBrowserServicePatchEnabled()) {
302 LOG(ERROR) << "Not running test. IBrowserServicePatch is in place.";
303 return;
304 }
305 MockWindowObserver win_observer_mock;
306 ScopedComPtr<IInternetSecurityManager> security_manager;
307 HRESULT hr = security_manager.CreateInstance(CLSID_InternetSecurityManager);
308 ASSERT_HRESULT_SUCCEEDED(hr);
309 // Add the server to restricted sites zone.
310 hr = security_manager->SetZoneMapping(URLZONE_UNTRUSTED,
311 GetTestUrl(L"").c_str(), SZM_CREATE);
312
313 EXPECT_CALL(ie_mock_, OnFileDownload(_, _))
314 .Times(testing::AnyNumber());
315 server_mock_.ExpectAndServeAnyRequests(GetParam());
316
317 ProtocolPatchMethod patch_method = GetPatchMethod();
318
319 const wchar_t* kDialogClass = L"#32770";
320 const char* kAlertDlgCaption = "Security Alert";
321
322 EXPECT_CALL(ie_mock_, OnBeforeNavigate2(_,
323 testing::Field(&VARIANT::bstrVal,
324 testing::StrCaseEq(GetSimplePageUrl())), _, _, _, _, _))
325 .Times(1)
326 .WillOnce(WatchWindow(&win_observer_mock, kDialogClass));
327
328 if (patch_method == PATCH_METHOD_INET_PROTOCOL) {
329 EXPECT_CALL(ie_mock_, OnBeforeNavigate2(_,
330 testing::Field(&VARIANT::bstrVal,
331 testing::HasSubstr(L"res://")), _, _, _, _, _))
332 .Times(testing::AtMost(1));
333 }
334
335 EXPECT_CALL(ie_mock_, OnNavigateComplete2(_,
336 testing::Field(&VARIANT::bstrVal, StrEq(GetSimplePageUrl()))))
337 .Times(testing::AtMost(1));
338
339 EXPECT_CALL(win_observer_mock, OnWindowDetected(_, StrEq(kAlertDlgCaption)))
340 .Times(1)
341 .WillOnce(testing::DoAll(
342 DoCloseWindow(),
343 CloseBrowserMock(&ie_mock_)));
344
345 LaunchIEAndNavigate(GetSimplePageUrl());
346
347 ASSERT_HRESULT_SUCCEEDED(security_manager->SetZoneMapping(URLZONE_UNTRUSTED,
348 GetTestUrl(L"").c_str(), SZM_DELETE));
349 }
350
351 // This test checks if window.open calls with target blank issued for a
352 // different domain make it back to IE instead of completing the navigation
353 // within Chrome. We validate this by initiating a navigation to a non existent
354 // url which ensures we would get an error during navigation.
355 // Marking this disabled as it leaves behind Chrome processes, at least on
356 // IE 6 XP (http://crbug.com/48732).
357 TEST_P(FullTabNavigationTest, DISABLED_JavascriptWindowOpenDifferentDomain) {
358 if (!GetParam().invokes_cf() || GetInstalledIEVersion() == IE_7) {
359 LOG(ERROR) << "Test disabled for this configuration.";
360 return;
361 }
362 std::wstring parent_url =
363 GetTestUrl(L"window_open.html?http://www.nonexistent.com");
364 MockIEEventSink new_window_mock;
365 ie_mock_.ExpectAnyNavigations();
366 new_window_mock.ExpectAnyNavigations();
367 server_mock_.ExpectAndServeAnyRequests(GetParam());
368
369 EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(), StrEq(parent_url)))
370 .WillOnce(DelaySendDoubleClick(&ie_mock_, &loop_, 0, 10, 10));
371
372 ie_mock_.ExpectNewWindow(&new_window_mock);
373
374 EXPECT_CALL(new_window_mock, OnNavigateError(_, _, _, _, _))
375 .Times(1)
376 .WillOnce(CloseBrowserMock(&new_window_mock));
377
378 EXPECT_CALL(new_window_mock, OnLoad(_, _))
379 .Times(testing::AtMost(1));
380
381 EXPECT_CALL(new_window_mock, OnQuit())
382 .Times(1)
383 .WillOnce(CloseBrowserMock(&ie_mock_));
384
385 // OnNavigateError can take a long time to fire.
386 LaunchIENavigateAndLoop(parent_url,
387 kChromeFrameLongNavigationTimeoutInSeconds * 4);
388 ASSERT_TRUE(new_window_mock.event_sink()->web_browser2() != NULL);
389 }
390
391 // Tests that a page that calls window.open can then close the popup.
392 // Marking this test as FLAKY initially as it relies on getting focus and user
393 // input which don't work correctly at times.
394 // http://code.google.com/p/chromium/issues/detail?id=26549
395 TEST_P(FullTabNavigationTest, FLAKY_JavascriptWindowOpenCanClose) {
396 std::wstring parent_url =
397 GetTestUrl(L"window_open.html?simple.html");
398 MockIEEventSink new_window_mock;
399 ie_mock_.ExpectAnyNavigations();
400 new_window_mock.ExpectAnyNavigations();
401 server_mock_.ExpectAndServeAnyRequests(GetParam());
402
403 // Sending 'A' to the renderer should cause window.open then window.close.
404 EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(), StrEq(parent_url)))
405 .WillOnce(DelaySendDoubleClick(&ie_mock_, &loop_, 0, 10, 10));
406
407 ie_mock_.ExpectNewWindow(&new_window_mock);
408
409 EXPECT_CALL(new_window_mock, OnLoad(_, StrEq(GetSimplePageUrl())))
410 .Times(testing::AtMost(2))
411 .WillOnce(testing::DoAll(
412 SetFocusToRenderer(&ie_mock_),
413 DelaySendChar(&loop_, 500, 'C', simulate_input::NONE)))
414 .WillOnce(testing::Return()); // just to stop a gmock warning
415
416 EXPECT_CALL(new_window_mock, OnQuit())
417 .WillOnce(CloseBrowserMock(&ie_mock_));
418
419 LaunchIEAndNavigate(parent_url);
420 }
421
422 // Parameter for tests using the NavigationTransitionTest fixture. Includes two
423 // pages, each with their own possible CF invocation.
424 struct NavigationTransitionTestParameter {
425 NavigationTransitionTestParameter(CFInvocation::Type type1,
426 CFInvocation::Type type2) {
427 page1_ = CFInvocation(type1);
428 page2_ = CFInvocation(type2);
429 }
430 CFInvocation page1_;
431 CFInvocation page2_;
432 };
433
434 // Parameterized test fixture for tests which test navigation transitions
435 // between two pages.
436 class NavigationTransitionTest
437 : public MockIEEventSinkTest,
438 public testing::TestWithParam<NavigationTransitionTestParameter> {
439 public:
440 NavigationTransitionTest() {}
441
442 virtual void SetUp() {
443 page1_ = GetParam().page1_;
444 page2_ = GetParam().page2_;
445 }
446
447 protected:
448 CFInvocation page1_;
449 CFInvocation page2_;
450 };
451
452 // This instantiates each parameterized test with some of the different CF
453 // invocation methods.
454 // TODO(kkania): Do not allow these tests to be cache the pages. This is used
455 // currently because otherwise the meta tags can cause double requests. Change
456 // ExpectAndServeRequestAllowCache to ExpectAndServeRequest when allowed.
457 INSTANTIATE_TEST_CASE_P(
458 IEToIE,
459 NavigationTransitionTest,
460 testing::Values(NavigationTransitionTestParameter(
461 CFInvocation::NONE, CFInvocation::NONE)));
462 INSTANTIATE_TEST_CASE_P(
463 IEToMetaTag,
464 NavigationTransitionTest,
465 testing::Values(NavigationTransitionTestParameter(
466 CFInvocation::NONE, CFInvocation::META_TAG)));
467 INSTANTIATE_TEST_CASE_P(
468 IEToHttpHeader,
469 NavigationTransitionTest,
470 testing::Values(NavigationTransitionTestParameter(
471 CFInvocation::NONE, CFInvocation::HTTP_HEADER)));
472 INSTANTIATE_TEST_CASE_P(
473 CFToCF,
474 NavigationTransitionTest,
475 testing::Values(NavigationTransitionTestParameter(
476 CFInvocation::META_TAG, CFInvocation::META_TAG)));
477 INSTANTIATE_TEST_CASE_P(
478 CFToIE,
479 NavigationTransitionTest,
480 testing::Values(NavigationTransitionTestParameter(
481 CFInvocation::META_TAG, CFInvocation::NONE)));
482
483 // Test window.open calls.
484 // Marking this test as FLAKY initially as it relies on getting focus and user
485 // input which don't work correctly at times.
486 // http://code.google.com/p/chromium/issues/detail?id=26549
487 TEST_P(NavigationTransitionTest, FLAKY_JavascriptWindowOpen) {
488 std::wstring parent_url = GetTestUrl(L"window_open.html?simple.html");
489 std::wstring new_window_url = GetSimplePageUrl();
490 testing::StrictMock<MockIEEventSink> new_window_mock;
491
492 ie_mock_.ExpectNavigation(page1_.invokes_cf(), parent_url);
493 server_mock_.ExpectAndServeRequestAllowCache(page1_, parent_url);
494 EXPECT_CALL(ie_mock_, OnLoad(page1_.invokes_cf(), StrEq(parent_url)))
495 .WillOnce(DelaySendDoubleClick(&ie_mock_, &loop_, 0, 10, 10));
496
497 // If the parent window is in CF, the child will load in CF regardless of
498 // whether the child page invokes CF.
499 bool expect_cf = page1_.invokes_cf() || page2_.invokes_cf();
500 ie_mock_.ExpectNewWindow(&new_window_mock);
501 new_window_mock.ExpectJavascriptWindowOpenNavigation(page1_.invokes_cf(),
502 expect_cf,
503 new_window_url);
504 EXPECT_CALL(server_mock_, Get(_, UrlPathEq(new_window_url), _))
505 .Times(testing::AtMost(1))
506 .WillOnce(SendAllowCacheResponse(&server_mock_, page2_));
507 EXPECT_CALL(new_window_mock, OnLoad(expect_cf, StrEq(new_window_url)))
508 .WillOnce(testing::DoAll(
509 ValidateWindowSize(&new_window_mock, 10, 10, 250, 250),
510 CloseBrowserMock(&new_window_mock)));
511
512 EXPECT_CALL(new_window_mock, OnQuit())
513 .WillOnce(CloseBrowserMock(&ie_mock_));
514
515 LaunchIENavigateAndLoop(parent_url,
516 kChromeFrameLongNavigationTimeoutInSeconds * 2);
517 }
518
519 // Test redirection with window.location in Javascript.
520 TEST_P(NavigationTransitionTest, FLAKY_JavascriptRedirection) {
521 if (GetInstalledIEVersion() == IE_7) {
522 LOG(ERROR) << "Test disabled for this configuration.";
523 return;
524 }
525 std::wstring redirect_url = GetTestUrl(L"javascript_redirect.html");
526
527 ie_mock_.ExpectNavigation(page1_.invokes_cf(), redirect_url);
528 server_mock_.ExpectAndServeRequestAllowCache(page1_, redirect_url);
529 EXPECT_CALL(ie_mock_, OnLoad(page1_.invokes_cf(), StrEq(redirect_url)))
530 .WillOnce(VerifyAddressBarUrl(&ie_mock_));
531
532 ie_mock_.ExpectNavigation(page2_.invokes_cf(), GetSimplePageUrl());
533 server_mock_.ExpectAndServeRequestAllowCache(page2_, GetSimplePageUrl());
534 EXPECT_CALL(ie_mock_, OnLoad(page2_.invokes_cf(), StrEq(GetSimplePageUrl())))
535 .WillOnce(testing::DoAll(
536 VerifyAddressBarUrl(&ie_mock_),
537 CloseBrowserMock(&ie_mock_)));
538
539 LaunchIEAndNavigate(redirect_url);
540 }
541
542 // Test following a link by TAB + ENTER.
543 TEST_P(NavigationTransitionTest, FLAKY_FollowLink) {
544 if (page1_.invokes_cf() && page2_.invokes_cf() &&
545 GetInstalledIEVersion() > IE_6) {
546 // For some reason IE 7 and 8 send two BeforeNavigate events for the second
547 // page for this case.
548 LOG(ERROR) << "Test disabled for this configuration.";
549 return;
550 }
551 ie_mock_.ExpectNavigation(page1_.invokes_cf(), GetLinkPageUrl());
552 server_mock_.ExpectAndServeRequestAllowCache(page1_, GetLinkPageUrl());
553 EXPECT_CALL(ie_mock_, OnLoad(page1_.invokes_cf(), StrEq(GetLinkPageUrl())))
554 .WillOnce(testing::DoAll(
555 SetFocusToRenderer(&ie_mock_),
556 DelaySendChar(&loop_, 500, VK_TAB, simulate_input::NONE),
557 DelaySendChar(&loop_, 1000, VK_RETURN, simulate_input::NONE)));
558
559 ie_mock_.ExpectNavigation(page2_.invokes_cf(), GetSimplePageUrl());
560 server_mock_.ExpectAndServeRequestAllowCache(page2_, GetSimplePageUrl());
561 EXPECT_CALL(ie_mock_, OnLoad(page2_.invokes_cf(), StrEq(GetSimplePageUrl())))
562 .WillOnce(testing::DoAll(
563 VerifyAddressBarUrl(&ie_mock_),
564 CloseBrowserMock(&ie_mock_)));
565
566 LaunchIEAndNavigate(GetLinkPageUrl());
567 }
568
569 // Basic navigation test fixture which uses the MockIEEventSink. These tests
570 // are not parameterized.
571 class NavigationTest : public MockIEEventSinkTest, public testing::Test {
572 public:
573 NavigationTest() {}
574 };
575
576 // gMock matcher which tests if a url is blank.
577 MATCHER(BlankUrl, "is \"\" or NULL") {
578 return arg == NULL || wcslen(arg) == 0;
579 }
580
581 // Test navigation to a disallowed url.
582 TEST_F(NavigationTest, DisallowedUrl) {
583 // If a navigation fails then IE issues a navigation to an interstitial
584 // page. Catch this to track navigation errors as the NavigateError
585 // notification does not seem to fire reliably.
586 const wchar_t disallowed_url[] = L"gcf:file:///C:/";
587
588 EXPECT_CALL(ie_mock_, OnBeforeNavigate2(_, testing::Field(&VARIANT::bstrVal,
589 StrEq(disallowed_url)),
590 _, _, _, _, _));
591 EXPECT_CALL(ie_mock_, OnLoad(IN_IE, BlankUrl()))
592 .Times(testing::AtMost(1));
593 EXPECT_CALL(ie_mock_, OnBeforeNavigate2(_, testing::Field(&VARIANT::bstrVal,
594 testing::StartsWith(L"res:")),
595 _, _, _, _, _));
596 EXPECT_CALL(ie_mock_, OnFileDownload(VARIANT_TRUE, _))
597 .Times(testing::AnyNumber())
598 .WillRepeatedly(testing::Return());
599 EXPECT_CALL(ie_mock_, OnNavigateComplete2(_, testing::Field(&VARIANT::bstrVal,
600 StrEq(disallowed_url))));
601 // Although we expect a load event for this, we should never receive a
602 // corresponding GET request.
603 EXPECT_CALL(ie_mock_, OnLoad(IN_IE, StrEq(disallowed_url)))
604 .WillOnce(CloseBrowserMock(&ie_mock_));
605
606 LaunchIEAndNavigate(disallowed_url);
607 }
608
609 // NOTE: This test is currently disabled as we haven't finished implementing
610 // support for this yet. The test (as written) works fine for IE. CF might
611 // have a different set of requirements once we fully support this and hence
612 // the test might need some refining before being enabled.
613 TEST_F(NavigationTest, DISABLED_DownloadInNewWindow) {
614 MockIEEventSink new_window_mock;
615 std::wstring kDownloadFromNewWin =
616 GetTestUrl(L"full_tab_download_from_new_window.html");
617
618 ie_mock_.ExpectNavigation(IN_CF, kDownloadFromNewWin);
619
620 EXPECT_CALL(ie_mock_, OnNewWindow3(_, _, _, _, _));
621
622 EXPECT_CALL(ie_mock_, OnNewBrowserWindow(_, _))
623 .WillOnce(testing::WithArgs<0>(testing::Invoke(testing::CreateFunctor(
624 &new_window_mock, &MockIEEventSink::Attach))));
625 EXPECT_CALL(new_window_mock, OnBeforeNavigate2(_, _, _, _, _, _, _));
626
627 EXPECT_CALL(new_window_mock, OnFileDownload(VARIANT_FALSE, _))
628 .Times(2)
629 .WillRepeatedly(CloseBrowserMock(&new_window_mock));
630
631 EXPECT_CALL(new_window_mock, OnNavigateComplete2(_, _));
632
633 EXPECT_CALL(new_window_mock, OnQuit()).WillOnce(CloseBrowserMock(&ie_mock_));
634
635 LaunchIEAndNavigate(kDownloadFromNewWin);
636 }
637
638 } // namespace chrome_frame_test
OLDNEW
« no previous file with comments | « chrome_frame/test/mock_ie_event_sink_test.cc ('k') | chrome_frame/test/no_interference_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698