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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 987923002: Add tests for navigation type classifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@subframe
Patch Set: creis Created 5 years, 9 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
« no previous file with comments | « no previous file | content/test/data/navigation_controller/page_with_links.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "content/browser/frame_host/frame_tree.h" 7 #include "content/browser/frame_host/frame_tree.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 EXPECT_TRUE(NavigateToURL(shell(), web_ui_page)); 151 EXPECT_TRUE(NavigateToURL(shell(), web_ui_page));
152 EXPECT_EQ(BINDINGS_POLICY_WEB_UI, 152 EXPECT_EQ(BINDINGS_POLICY_WEB_UI,
153 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); 153 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings());
154 154
155 ShellAddedObserver observer; 155 ShellAddedObserver observer;
156 std::string page_url = embedded_test_server()->GetURL( 156 std::string page_url = embedded_test_server()->GetURL(
157 "/navigation_controller/simple_page_1.html").spec(); 157 "/navigation_controller/simple_page_1.html").spec();
158 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), 158 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
159 "window.open('" + page_url + "', '_blank')")); 159 "window.open('" + page_url + "', '_blank')"));
160 Shell* shell2 = observer.GetShell(); 160 Shell* shell2 = observer.GetShell();
161 WaitForLoadStop(shell2->web_contents()); 161 EXPECT_TRUE(WaitForLoadStop(shell2->web_contents()));
162 162
163 EXPECT_EQ(1, shell2->web_contents()->GetController().GetEntryCount()); 163 EXPECT_EQ(1, shell2->web_contents()->GetController().GetEntryCount());
164 EXPECT_EQ(1, RendererHistoryLength(shell2)); 164 EXPECT_EQ(1, RendererHistoryLength(shell2));
165 165
166 // Again, as above, there's no way to access the renderer's notion of the 166 // Again, as above, there's no way to access the renderer's notion of the
167 // history offset via JavaScript. Checking just the history length, again, 167 // history offset via JavaScript. Checking just the history length, again,
168 // will have to suffice. 168 // will have to suffice.
169 } 169 }
170 170
171 namespace { 171 namespace {
172 172
173 struct FrameNavigateParamsCapturer : public WebContentsObserver { 173 class FrameNavigateParamsCapturer : public WebContentsObserver {
174 public: 174 public:
175 // Observes navigation for the specified |node|. 175 // Observes navigation for the specified |node|.
176 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) 176 explicit FrameNavigateParamsCapturer(FrameTreeNode* node)
177 : WebContentsObserver( 177 : WebContentsObserver(
178 node->current_frame_host()->delegate()->GetAsWebContents()), 178 node->current_frame_host()->delegate()->GetAsWebContents()),
179 frame_tree_node_id_(node->frame_tree_node_id()), 179 frame_tree_node_id_(node->frame_tree_node_id()),
180 message_loop_runner_(new MessageLoopRunner) {} 180 message_loop_runner_(new MessageLoopRunner) {}
181 181
182 void Wait() { 182 void Wait() {
183 message_loop_runner_->Run(); 183 message_loop_runner_->Run();
(...skipping 11 matching lines...) Expand all
195 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, 195 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
196 const LoadCommittedDetails& details, 196 const LoadCommittedDetails& details,
197 const FrameNavigateParams& params) override { 197 const FrameNavigateParams& params) override {
198 RenderFrameHostImpl* rfh = 198 RenderFrameHostImpl* rfh =
199 static_cast<RenderFrameHostImpl*>(render_frame_host); 199 static_cast<RenderFrameHostImpl*>(render_frame_host);
200 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) 200 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_)
201 return; 201 return;
202 202
203 params_ = params; 203 params_ = params;
204 details_ = details; 204 details_ = details;
205 if (!web_contents()->IsLoading())
206 message_loop_runner_->Quit();
207 }
208
209 void DidStopLoading(RenderViewHost* render_view_host) override {
205 message_loop_runner_->Quit(); 210 message_loop_runner_->Quit();
206 } 211 }
207 212
208 // The id of the FrameTreeNode whose navigations to observe. 213 // The id of the FrameTreeNode whose navigations to observe.
209 int frame_tree_node_id_; 214 int frame_tree_node_id_;
210 215
211 // The params of the last navigation. 216 // The params of the last navigation.
212 FrameNavigateParams params_; 217 FrameNavigateParams params_;
213 218
214 // The details of the last navigation. 219 // The details of the last navigation.
215 LoadCommittedDetails details_; 220 LoadCommittedDetails details_;
216 221
217 // The MessageLoopRunner used to spin the message loop. 222 // The MessageLoopRunner used to spin the message loop.
218 scoped_refptr<MessageLoopRunner> message_loop_runner_; 223 scoped_refptr<MessageLoopRunner> message_loop_runner_;
219 }; 224 };
220 225
221 struct LoadCommittedCapturer : public WebContentsObserver { 226 class LoadCommittedCapturer : public WebContentsObserver {
222 public: 227 public:
223 // Observes the load commit for the specified |node|. 228 // Observes the load commit for the specified |node|.
224 explicit LoadCommittedCapturer(FrameTreeNode* node) 229 explicit LoadCommittedCapturer(FrameTreeNode* node)
225 : WebContentsObserver( 230 : WebContentsObserver(
226 node->current_frame_host()->delegate()->GetAsWebContents()), 231 node->current_frame_host()->delegate()->GetAsWebContents()),
227 frame_tree_node_id_(node->frame_tree_node_id()), 232 frame_tree_node_id_(node->frame_tree_node_id()),
228 message_loop_runner_(new MessageLoopRunner) {} 233 message_loop_runner_(new MessageLoopRunner) {}
229 234
230 // Observes the load commit for the next created frame in the specified 235 // Observes the load commit for the next created frame in the specified
231 // |web_contents|. 236 // |web_contents|.
(...skipping 24 matching lines...) Expand all
256 RenderFrameHost* render_frame_host, 261 RenderFrameHost* render_frame_host,
257 const GURL& url, 262 const GURL& url,
258 ui::PageTransition transition_type) override { 263 ui::PageTransition transition_type) override {
259 DCHECK_NE(0, frame_tree_node_id_); 264 DCHECK_NE(0, frame_tree_node_id_);
260 RenderFrameHostImpl* rfh = 265 RenderFrameHostImpl* rfh =
261 static_cast<RenderFrameHostImpl*>(render_frame_host); 266 static_cast<RenderFrameHostImpl*>(render_frame_host);
262 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) 267 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_)
263 return; 268 return;
264 269
265 transition_type_ = transition_type; 270 transition_type_ = transition_type;
271 if (!web_contents()->IsLoading())
272 message_loop_runner_->Quit();
273 }
274
275 void DidStopLoading(RenderViewHost* render_view_host) override {
266 message_loop_runner_->Quit(); 276 message_loop_runner_->Quit();
267 } 277 }
268 278
269 // The id of the FrameTreeNode whose navigations to observe. 279 // The id of the FrameTreeNode whose navigations to observe.
270 int frame_tree_node_id_; 280 int frame_tree_node_id_;
271 281
272 // The transition_type of the last navigation. 282 // The transition_type of the last navigation.
273 ui::PageTransition transition_type_; 283 ui::PageTransition transition_type_;
274 284
275 // The MessageLoopRunner used to spin the message loop. 285 // The MessageLoopRunner used to spin the message loop.
276 scoped_refptr<MessageLoopRunner> message_loop_runner_; 286 scoped_refptr<MessageLoopRunner> message_loop_runner_;
277 }; 287 };
278 288
279 } // namespace 289 } // namespace
280 290
281 // Verify that the distinction between manual and auto subframes is properly set 291 // Various tests for navigation type classifications. TODO(avi): It's rather
282 // for subframe navigations. TODO(avi): It's rather bogus that the same info is 292 // bogus that the same info is in two different enums; http://crbug.com/453555.
283 // in two different enums; http://crbug.com/453555. 293
294 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly
295 // classified.
296 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
297 NavigationTypeClassification_NewPage) {
298 NavigateToURL(shell(), GURL("about:blank"));
299
300 FrameTreeNode* root =
301 static_cast<WebContentsImpl*>(shell()->web_contents())->
302 GetFrameTree()->root();
303
304 {
305 // Simple load.
306 FrameNavigateParamsCapturer capturer(root);
307 GURL frame_url(embedded_test_server()->GetURL(
308 "/navigation_controller/page_with_links.html"));
309 NavigateFrameToURL(root, frame_url);
310 capturer.Wait();
311 // TODO(avi,creis): Why is this (and quite a few others below) a "link"
312 // transition? Lots of these transitions should be cleaned up.
313 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition);
314 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
315 }
316
317 {
318 // Load via a fragment link click.
319 FrameNavigateParamsCapturer capturer(root);
320 std::string script = "document.getElementById('fraglink').click()";
321 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
322 capturer.Wait();
323 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition);
324 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
325 }
326
327 {
328 // Load via link click.
329 FrameNavigateParamsCapturer capturer(root);
330 std::string script = "document.getElementById('thelink').click()";
331 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
332 capturer.Wait();
333 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition);
334 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
335 }
336
337 {
338 // location.assign().
339 FrameNavigateParamsCapturer capturer(root);
340 GURL frame_url(embedded_test_server()->GetURL(
341 "/navigation_controller/simple_page_2.html"));
342 std::string script = "location.assign('" + frame_url.spec() + "')";
343 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
344 capturer.Wait();
345 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
346 capturer.params().transition);
347 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
348 }
349
350 {
351 // history.pushState().
352 FrameNavigateParamsCapturer capturer(root);
353 std::string script =
354 "history.pushState({}, 'page 1', 'simple_page_1.html')";
355 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
356 capturer.Wait();
357 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
358 capturer.params().transition);
359 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
360 }
361 }
362
363 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly
364 // classified.
365 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
366 NavigationTypeClassification_ExistingPage) {
367 GURL url1(embedded_test_server()->GetURL(
368 "/navigation_controller/simple_page_1.html"));
369 NavigateToURL(shell(), url1);
370 GURL url2(embedded_test_server()->GetURL(
371 "/navigation_controller/simple_page_2.html"));
372 NavigateToURL(shell(), url2);
373
374 FrameTreeNode* root =
375 static_cast<WebContentsImpl*>(shell()->web_contents())->
376 GetFrameTree()->root();
377
378 {
379 // Back.
380 FrameNavigateParamsCapturer capturer(root);
381 shell()->web_contents()->GetController().GoBack();
382 capturer.Wait();
383 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED
384 | ui::PAGE_TRANSITION_FORWARD_BACK
385 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR,
386 capturer.params().transition);
387 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
388 }
389
390 {
391 // Forward.
392 FrameNavigateParamsCapturer capturer(root);
393 shell()->web_contents()->GetController().GoForward();
394 capturer.Wait();
395 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED
396 | ui::PAGE_TRANSITION_FORWARD_BACK
397 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR,
398 capturer.params().transition);
399 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
400 }
401
402 {
403 // Reload from the browser side.
404 FrameNavigateParamsCapturer capturer(root);
405 shell()->web_contents()->GetController().Reload(false);
406 capturer.Wait();
407 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, capturer.params().transition);
408 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
409 }
410
411 {
412 // Reload from the renderer side.
413 FrameNavigateParamsCapturer capturer(root);
414 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(),
415 "location.reload()"));
416 capturer.Wait();
417 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
418 capturer.params().transition);
419 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
420 }
421
422 {
423 // location.replace().
424 FrameNavigateParamsCapturer capturer(root);
425 GURL frame_url(embedded_test_server()->GetURL(
426 "/navigation_controller/simple_page_1.html"));
427 std::string script = "location.replace('" + frame_url.spec() + "')";
428 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
429 capturer.Wait();
430 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
431 capturer.params().transition);
432 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
433 }
434 }
435
436 // Verify that navigations for NAVIGATION_TYPE_SAME_PAGE are correctly
437 // classified.
438 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
439 NavigationTypeClassification_SamePage) {
440 GURL url1(embedded_test_server()->GetURL(
441 "/navigation_controller/simple_page_1.html"));
442 NavigateToURL(shell(), url1);
443
444 FrameTreeNode* root =
445 static_cast<WebContentsImpl*>(shell()->web_contents())->
446 GetFrameTree()->root();
447
448 {
449 // Simple load.
450 FrameNavigateParamsCapturer capturer(root);
451 GURL frame_url(embedded_test_server()->GetURL(
452 "/navigation_controller/simple_page_1.html"));
453 NavigateFrameToURL(root, frame_url);
454 capturer.Wait();
455 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition);
456 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, capturer.details().type);
457 }
458 }
459
460 // Verify that navigations for NAVIGATION_TYPE_IN_PAGE are correctly
461 // classified.
462 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
463 NavigationTypeClassification_InPage) {
464 GURL url1(embedded_test_server()->GetURL(
465 "/navigation_controller/simple_page_1.html"));
466 NavigateToURL(shell(), url1);
467
468 FrameTreeNode* root =
469 static_cast<WebContentsImpl*>(shell()->web_contents())->
470 GetFrameTree()->root();
471
472 {
473 // history.replaceState().
474 FrameNavigateParamsCapturer capturer(root);
475 std::string script =
476 "history.replaceState({}, 'page 1', 'simple_page_2.html')";
477 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
478 capturer.Wait();
479 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, capturer.params().transition);
480 // TODO(avi,creis): Huh? Why is this not NAVIGATION_TYPE_EXISTING_PAGE like
Charlie Reis 2015/03/09 22:04:05 Remove this TODO?
Avi (use Gerrit) 2015/03/09 22:50:19 Done.
481 // location.replace()?
482 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type);
483 }
484
485 // Back and forward across a fragment navigation.
486
487 GURL url2(embedded_test_server()->GetURL(
488 "/navigation_controller/page_with_links.html"));
489 NavigateToURL(shell(), url2);
490 std::string script = "document.getElementById('fraglink').click()";
491 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
492 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
493
494 {
495 // Back.
496 FrameNavigateParamsCapturer capturer(root);
497 shell()->web_contents()->GetController().GoBack();
498 capturer.Wait();
499 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED
500 | ui::PAGE_TRANSITION_FORWARD_BACK
501 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR,
502 capturer.params().transition);
503 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type);
504 }
505
506 {
507 // Forward.
508 FrameNavigateParamsCapturer capturer(root);
509 shell()->web_contents()->GetController().GoForward();
510 capturer.Wait();
511 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FORWARD_BACK,
512 capturer.params().transition);
513 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type);
514 }
515
516 // Back and forward across a pushState-created navigation.
517
518 NavigateToURL(shell(), url1);
519 script = "history.pushState({}, 'page 2', 'simple_page_2.html')";
520 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
521 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
522
523 {
524 // Back.
525 FrameNavigateParamsCapturer capturer(root);
526 shell()->web_contents()->GetController().GoBack();
527 capturer.Wait();
528 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED
529 | ui::PAGE_TRANSITION_FORWARD_BACK
530 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR,
531 capturer.params().transition);
532 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type);
533 }
534
535 {
536 // Forward.
537 FrameNavigateParamsCapturer capturer(root);
538 shell()->web_contents()->GetController().GoForward();
539 capturer.Wait();
540 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FORWARD_BACK,
541 capturer.params().transition);
542 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type);
543 }
544 }
545
546 // Verify that navigations for NAVIGATION_TYPE_NEW_SUBFRAME and
547 // NAVIGATION_TYPE_AUTO_SUBFRAME are properly classified.
284 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 548 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
285 NavigationTypeClassification_NewAndAutoSubframe) { 549 NavigationTypeClassification_NewAndAutoSubframe) {
286 GURL main_url(embedded_test_server()->GetURL( 550 GURL main_url(embedded_test_server()->GetURL(
287 "/navigation_controller/page_with_iframe.html")); 551 "/navigation_controller/page_with_iframe.html"));
288 NavigateToURL(shell(), main_url); 552 NavigateToURL(shell(), main_url);
289 553
290 // It is safe to obtain the root frame tree node here, as it doesn't change. 554 // It is safe to obtain the root frame tree node here, as it doesn't change.
291 FrameTreeNode* root = 555 FrameTreeNode* root =
292 static_cast<WebContentsImpl*>(shell()->web_contents())-> 556 static_cast<WebContentsImpl*>(shell()->web_contents())->
293 GetFrameTree()->root(); 557 GetFrameTree()->root();
294 558
295 ASSERT_EQ(1U, root->child_count()); 559 ASSERT_EQ(1U, root->child_count());
296 ASSERT_NE(nullptr, root->child_at(0)); 560 ASSERT_NE(nullptr, root->child_at(0));
297 561
298 { 562 {
299 // Navigate the iframe to a new URL; expect a manual subframe transition. 563 // Simple load.
300 FrameNavigateParamsCapturer capturer(root->child_at(0)); 564 FrameNavigateParamsCapturer capturer(root->child_at(0));
301 GURL frame_url(embedded_test_server()->GetURL( 565 GURL frame_url(embedded_test_server()->GetURL(
302 "/navigation_controller/simple_page_1.html")); 566 "/navigation_controller/simple_page_1.html"));
303 NavigateFrameToURL(root->child_at(0), frame_url); 567 NavigateFrameToURL(root->child_at(0), frame_url);
304 capturer.Wait(); 568 capturer.Wait();
305 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, 569 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
306 capturer.params().transition); 570 capturer.params().transition);
307 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); 571 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
308 } 572 }
309 573
310 { 574 {
311 // Do a history navigation; expect an auto subframe transition. 575 // Back.
312 FrameNavigateParamsCapturer capturer(root->child_at(0)); 576 FrameNavigateParamsCapturer capturer(root->child_at(0));
313 shell()->web_contents()->GetController().GoBack(); 577 shell()->web_contents()->GetController().GoBack();
314 capturer.Wait(); 578 capturer.Wait();
315 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); 579 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition);
316 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); 580 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type);
317 } 581 }
318 582
319 { 583 {
320 // Do a history navigation; expect an auto subframe transition. 584 // Forward.
321 FrameNavigateParamsCapturer capturer(root->child_at(0)); 585 FrameNavigateParamsCapturer capturer(root->child_at(0));
322 shell()->web_contents()->GetController().GoForward(); 586 shell()->web_contents()->GetController().GoForward();
323 capturer.Wait(); 587 capturer.Wait();
324 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); 588 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition);
325 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); 589 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type);
326 } 590 }
327 591
328 { 592 {
329 // Navigate the iframe to a new URL; expect a manual subframe transition. 593 // Simple load.
330 FrameNavigateParamsCapturer capturer(root->child_at(0)); 594 FrameNavigateParamsCapturer capturer(root->child_at(0));
331 GURL frame_url(embedded_test_server()->GetURL( 595 GURL frame_url(embedded_test_server()->GetURL(
332 "/navigation_controller/simple_page_2.html")); 596 "/navigation_controller/page_with_links.html"));
333 NavigateFrameToURL(root->child_at(0), frame_url); 597 NavigateFrameToURL(root->child_at(0), frame_url);
334 capturer.Wait(); 598 capturer.Wait();
335 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, 599 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
336 capturer.params().transition); 600 capturer.params().transition);
337 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); 601 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
338 } 602 }
339 603
340 { 604 {
341 // Use location.assign(); expect a manual subframe transition. 605 // Load via a fragment link click.
606 FrameNavigateParamsCapturer capturer(root->child_at(0));
607 std::string script = "document.getElementById('fraglink').click()";
608 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(),
609 script));
610 capturer.Wait();
611 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
612 capturer.params().transition);
613 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
614 }
615
616 {
617 // location.assign().
342 FrameNavigateParamsCapturer capturer(root->child_at(0)); 618 FrameNavigateParamsCapturer capturer(root->child_at(0));
343 GURL frame_url(embedded_test_server()->GetURL( 619 GURL frame_url(embedded_test_server()->GetURL(
344 "/navigation_controller/simple_page_1.html")); 620 "/navigation_controller/simple_page_1.html"));
345 std::string script = "location.assign('" + frame_url.spec() + "')"; 621 std::string script = "location.assign('" + frame_url.spec() + "')";
346 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), 622 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(),
347 script)); 623 script));
348 capturer.Wait(); 624 capturer.Wait();
349 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, 625 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
350 capturer.params().transition); 626 capturer.params().transition);
351 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); 627 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
352 } 628 }
353 629
354 { 630 {
355 // Use location.replace(); expect an auto subframe transition. (Replacements 631 // location.replace().
356 // aren't "navigation" so we only see the frame load committing.)
357 LoadCommittedCapturer capturer(root->child_at(0)); 632 LoadCommittedCapturer capturer(root->child_at(0));
358 GURL frame_url(embedded_test_server()->GetURL( 633 GURL frame_url(embedded_test_server()->GetURL(
359 "/navigation_controller/simple_page_2.html")); 634 "/navigation_controller/simple_page_2.html"));
360 std::string script = "location.replace('" + frame_url.spec() + "')"; 635 std::string script = "location.replace('" + frame_url.spec() + "')";
361 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), 636 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(),
362 script)); 637 script));
363 capturer.Wait(); 638 capturer.Wait();
364 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 639 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
365 } 640 }
366 641
367 { 642 {
368 // Use history.pushState(); expect a manual subframe transition. 643 // history.pushState().
369 FrameNavigateParamsCapturer capturer(root->child_at(0)); 644 FrameNavigateParamsCapturer capturer(root->child_at(0));
370 std::string script = 645 std::string script =
371 "history.pushState({}, 'page 1', 'simple_page_1.html')"; 646 "history.pushState({}, 'page 1', 'simple_page_1.html')";
372 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), 647 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(),
373 script)); 648 script));
374 capturer.Wait(); 649 capturer.Wait();
375 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, 650 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
376 capturer.params().transition); 651 capturer.params().transition);
377 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); 652 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
378 } 653 }
379 654
380 { 655 {
381 // Use history.replaceState(); expect an auto subframe transition. 656 // history.replaceState().
382 // (Replacements aren't "navigation" so we only see the frame load
383 // committing.)
384 LoadCommittedCapturer capturer(root->child_at(0)); 657 LoadCommittedCapturer capturer(root->child_at(0));
385 std::string script = 658 std::string script =
386 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; 659 "history.replaceState({}, 'page 2', 'simple_page_2.html')";
387 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), 660 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(),
388 script)); 661 script));
389 capturer.Wait(); 662 capturer.Wait();
390 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 663 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
391 } 664 }
392 665
393 { 666 {
394 // Reload the subframe; expect an auto subframe transition. (Reloads aren't 667 // Reload.
395 // "navigation" so we only see the frame load committing.)
396 LoadCommittedCapturer capturer(root->child_at(0)); 668 LoadCommittedCapturer capturer(root->child_at(0));
397 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), 669 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(),
398 "location.reload()")); 670 "location.reload()"));
399 capturer.Wait(); 671 capturer.Wait();
400 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 672 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
401 } 673 }
402 674
403 { 675 {
404 // Create an iframe; expect an auto subframe transition. (Initial frame 676 // Create an iframe.
405 // creation isn't "navigation" so we only see the frame load committing.)
406 LoadCommittedCapturer capturer(shell()->web_contents()); 677 LoadCommittedCapturer capturer(shell()->web_contents());
407 GURL frame_url(embedded_test_server()->GetURL( 678 GURL frame_url(embedded_test_server()->GetURL(
408 "/navigation_controller/simple_page_1.html")); 679 "/navigation_controller/simple_page_1.html"));
409 std::string script = "var iframe = document.createElement('iframe');" 680 std::string script = "var iframe = document.createElement('iframe');"
410 "iframe.src = '" + frame_url.spec() + "';" 681 "iframe.src = '" + frame_url.spec() + "';"
411 "document.body.appendChild(iframe);"; 682 "document.body.appendChild(iframe);";
412 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 683 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
413 capturer.Wait(); 684 capturer.Wait();
414 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 685 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
415 } 686 }
416 } 687 }
417 688
418 } // namespace content 689 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/test/data/navigation_controller/page_with_links.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698