OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 controller().LoadURL( | 398 controller().LoadURL( |
399 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 399 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
400 | 400 |
401 NavigationEntry* entry = controller().GetVisibleEntry(); | 401 NavigationEntry* entry = controller().GetVisibleEntry(); |
402 ASSERT_EQ(kGURL, entry->GetURL()); | 402 ASSERT_EQ(kGURL, entry->GetURL()); |
403 entry->SetTitle(title); | 403 entry->SetTitle(title); |
404 | 404 |
405 EXPECT_EQ(title, contents()->GetTitle()); | 405 EXPECT_EQ(title, contents()->GetTitle()); |
406 } | 406 } |
407 | 407 |
408 // Test view source mode for a webui page. | 408 // A page shouldn't be able to open view-source for a webui page. |
409 TEST_F(WebContentsImplTest, NTPViewSource) { | 409 TEST_F(WebContentsImplTest, ContentInitiatedViewSource) { |
410 NavigationControllerImpl& cont = | 410 NavigationControllerImpl& cont = |
411 static_cast<NavigationControllerImpl&>(controller()); | 411 static_cast<NavigationControllerImpl&>(controller()); |
412 const char kUrl[] = "view-source:chrome://blah"; | 412 const GURL kGURL("view-source:chrome://blah"); |
413 const GURL kGURL(kUrl); | 413 // NavigationControllerImpl rewrites view-source URLs, simulating that here. |
414 const GURL kRewrittenURL("chrome://blah"); | |
414 | 415 |
415 process()->sink().ClearMessages(); | 416 process()->sink().ClearMessages(); |
416 | 417 |
417 cont.LoadURL( | 418 // Use LoadURLWithParams instead of LoadURL, because the former properly |
418 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 419 // rewrites view-source:chrome://blah URLs to chrome://blah. |
420 NavigationController::LoadURLParams load_params(kGURL); | |
421 load_params.transition_type = ui::PAGE_TRANSITION_TYPED; | |
422 load_params.extra_headers = "content-type: text/plain"; | |
423 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; | |
424 load_params.is_renderer_initiated = false; | |
Charlie Reis
2016/05/23 22:32:16
Why is this set to false? The test name and comme
meacer
2016/05/23 23:57:47
Ah, I changed this to test browser-initiated navig
| |
425 controller().LoadURLWithParams(load_params); | |
426 | |
419 int entry_id = cont.GetPendingEntry()->GetUniqueID(); | 427 int entry_id = cont.GetPendingEntry()->GetUniqueID(); |
420 // Did we get the expected message? | 428 // Did we get the expected message? |
421 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( | 429 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( |
422 FrameMsg_EnableViewSourceMode::ID)); | 430 FrameMsg_EnableViewSourceMode::ID)); |
423 | 431 |
424 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 432 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
425 InitNavigateParams(¶ms, 0, entry_id, true, kGURL, | 433 InitNavigateParams(¶ms, 0, entry_id, true, kRewrittenURL, |
426 ui::PAGE_TRANSITION_TYPED); | 434 ui::PAGE_TRANSITION_TYPED); |
427 contents()->GetMainFrame()->PrepareForCommit(); | 435 contents()->GetMainFrame()->PrepareForCommit(); |
428 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 436 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
429 // Also check title and url. | 437 EXPECT_EQ(base::ASCIIToUTF16("chrome://blah"), contents()->GetTitle()); |
430 EXPECT_EQ(base::ASCIIToUTF16(kUrl), contents()->GetTitle()); | |
431 } | 438 } |
432 | 439 |
433 // Test to ensure UpdateMaxPageID is working properly. | 440 // Test to ensure UpdateMaxPageID is working properly. |
434 TEST_F(WebContentsImplTest, UpdateMaxPageID) { | 441 TEST_F(WebContentsImplTest, UpdateMaxPageID) { |
435 SiteInstance* instance1 = contents()->GetSiteInstance(); | 442 SiteInstance* instance1 = contents()->GetSiteInstance(); |
436 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(nullptr)); | 443 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(nullptr)); |
437 | 444 |
438 // Starts at -1. | 445 // Starts at -1. |
439 EXPECT_EQ(-1, contents()->GetMaxPageID()); | 446 EXPECT_EQ(-1, contents()->GetMaxPageID()); |
440 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance1)); | 447 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance1)); |
(...skipping 3012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3453 // An automatic navigation. | 3460 // An automatic navigation. |
3454 contents()->GetMainFrame()->SendNavigateWithModificationCallback( | 3461 contents()->GetMainFrame()->SendNavigateWithModificationCallback( |
3455 2, 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); | 3462 2, 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); |
3456 | 3463 |
3457 EXPECT_EQ(1u, dialog_manager.reset_count()); | 3464 EXPECT_EQ(1u, dialog_manager.reset_count()); |
3458 | 3465 |
3459 contents()->SetJavaScriptDialogManagerForTesting(nullptr); | 3466 contents()->SetJavaScriptDialogManagerForTesting(nullptr); |
3460 } | 3467 } |
3461 | 3468 |
3462 } // namespace content | 3469 } // namespace content |
OLD | NEW |