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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 1917073002: Block webpages from navigating to view-source URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete layout tests Created 4 years, 6 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
OLDNEW
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
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 // Browser initiated navigations to view-source URLs of WebUI pages should work.
409 TEST_F(WebContentsImplTest, NTPViewSource) { 409 TEST_F(WebContentsImplTest, DirectNavigationToViewSourceWebUI) {
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;
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(&params, 0, entry_id, true, kGURL, 433 InitNavigateParams(&params, 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(&params); 436 contents()->GetMainFrame()->SendNavigateWithParams(&params);
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 3013 matching lines...) Expand 10 before | Expand all | Expand 10 after
3454 // An automatic navigation. 3461 // An automatic navigation.
3455 contents()->GetMainFrame()->SendNavigateWithModificationCallback( 3462 contents()->GetMainFrame()->SendNavigateWithModificationCallback(
3456 2, 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); 3463 2, 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture));
3457 3464
3458 EXPECT_EQ(1u, dialog_manager.reset_count()); 3465 EXPECT_EQ(1u, dialog_manager.reset_count());
3459 3466
3460 contents()->SetJavaScriptDialogManagerForTesting(nullptr); 3467 contents()->SetJavaScriptDialogManagerForTesting(nullptr);
3461 } 3468 }
3462 3469
3463 } // namespace content 3470 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl_browsertest.cc ('k') | content/public/test/content_browser_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698