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

Side by Side Diff: chrome/browser/ui/search/new_tab_page_interceptor_browsertest.cc

Issue 2805133004: Local NTP: Deploy strict-dynamic CSP (Closed)
Patch Set: rebase Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/threading/sequenced_worker_pool.h" 8 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/search/search.h" 10 #include "chrome/browser/search/search.h"
(...skipping 22 matching lines...) Expand all
33 BrowserThread::GetBlockingPool()); 33 BrowserThread::GetBlockingPool());
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 37
38 class NewTabPageInterceptorTest : public InProcessBrowserTest { 38 class NewTabPageInterceptorTest : public InProcessBrowserTest {
39 public: 39 public:
40 NewTabPageInterceptorTest() {} 40 NewTabPageInterceptorTest() {}
41 41
42 void SetUpOnMainThread() override { 42 void SetUpOnMainThread() override {
43 path_ = ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath()); 43 base::FilePath path =
44 ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath());
44 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 45 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
45 base::BindOnce(&SetUrlRequestMock, path_)); 46 base::BindOnce(&SetUrlRequestMock, path));
46 } 47 }
47 48
48 const GURL& new_tab_url() const { return new_tab_url_; }
49 void set_new_tab_url(const GURL& url) { new_tab_url_ = url; }
50
51 void ChangeDefaultSearchProvider(const char* new_tab_path) { 49 void ChangeDefaultSearchProvider(const char* new_tab_path) {
52 TemplateURLService* template_url_service = 50 TemplateURLService* template_url_service =
53 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 51 TemplateURLServiceFactory::GetForProfile(browser()->profile());
54 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); 52 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
55 UIThreadSearchTermsData::SetGoogleBaseURL("https://mock.http/"); 53 UIThreadSearchTermsData::SetGoogleBaseURL("https://mock.http/");
56 std::string base_url("{google:baseURL}"); 54 std::string base_url("{google:baseURL}");
57 TemplateURLData data; 55 TemplateURLData data;
58 data.SetShortName(base::ASCIIToUTF16("Google")); 56 data.SetShortName(base::ASCIIToUTF16("Google"));
59 data.SetKeyword(base::UTF8ToUTF16(base_url)); 57 data.SetKeyword(base::UTF8ToUTF16(base_url));
60 data.SetURL(base_url + "url?bar={searchTerms}"); 58 data.SetURL(base_url + "url?bar={searchTerms}");
61 data.new_tab_url = base_url + new_tab_path; 59 data.new_tab_url = base_url + new_tab_path;
62 TemplateURL* template_url = 60 TemplateURL* template_url =
63 template_url_service->Add(base::MakeUnique<TemplateURL>(data)); 61 template_url_service->Add(base::MakeUnique<TemplateURL>(data));
64 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 62 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
65 } 63 }
66
67 private:
68 GURL new_tab_url_;
69 base::FilePath path_;
70 }; 64 };
71 65
72 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, NoInterception) { 66 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, NoInterception) {
73 set_new_tab_url( 67 GURL new_tab_url =
74 net::URLRequestMockHTTPJob::GetMockHttpsUrl("instant_extended.html")); 68 net::URLRequestMockHTTPJob::GetMockHttpsUrl("instant_extended.html");
75 ChangeDefaultSearchProvider("instant_extended.html"); 69 ChangeDefaultSearchProvider("instant_extended.html");
76 70
77 ui_test_utils::NavigateToURL(browser(), new_tab_url()); 71 ui_test_utils::NavigateToURL(browser(), new_tab_url);
78 content::WebContents* contents = 72 content::WebContents* contents =
79 browser()->tab_strip_model()->GetWebContentsAt(0); 73 browser()->tab_strip_model()->GetWebContentsAt(0);
80 content::NavigationController* controller = &contents->GetController();
81 // A correct, 200-OK file works correctly. 74 // A correct, 200-OK file works correctly.
82 EXPECT_EQ(new_tab_url(), controller->GetLastCommittedEntry()->GetURL()); 75 EXPECT_EQ(new_tab_url,
76 contents->GetController().GetLastCommittedEntry()->GetURL());
83 } 77 }
84 78
85 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, 404Interception) { 79 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, 404Interception) {
86 set_new_tab_url(net::URLRequestMockHTTPJob::GetMockHttpsUrl("page404.html")); 80 GURL new_tab_url =
81 net::URLRequestMockHTTPJob::GetMockHttpsUrl("page404.html");
87 ChangeDefaultSearchProvider("page404.html"); 82 ChangeDefaultSearchProvider("page404.html");
88 83
89 ui_test_utils::NavigateToURL(browser(), new_tab_url()); 84 ui_test_utils::NavigateToURL(browser(), new_tab_url);
90 content::WebContents* contents = 85 content::WebContents* contents =
91 browser()->tab_strip_model()->GetWebContentsAt(0); 86 browser()->tab_strip_model()->GetWebContentsAt(0);
92 content::NavigationController* controller = &contents->GetController();
93 // 404 makes a redirect to the local NTP. 87 // 404 makes a redirect to the local NTP.
94 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 88 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
95 controller->GetLastCommittedEntry()->GetURL()); 89 contents->GetController().GetLastCommittedEntry()->GetURL());
96 } 90 }
97 91
98 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, 204Interception) { 92 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, 204Interception) {
99 set_new_tab_url(net::URLRequestMockHTTPJob::GetMockHttpsUrl("page204.html")); 93 GURL new_tab_url =
94 net::URLRequestMockHTTPJob::GetMockHttpsUrl("page204.html");
100 ChangeDefaultSearchProvider("page204.html"); 95 ChangeDefaultSearchProvider("page204.html");
101 96
102 ui_test_utils::NavigateToURL(browser(), new_tab_url()); 97 ui_test_utils::NavigateToURL(browser(), new_tab_url);
103 content::WebContents* contents = 98 content::WebContents* contents =
104 browser()->tab_strip_model()->GetWebContentsAt(0); 99 browser()->tab_strip_model()->GetWebContentsAt(0);
105 content::NavigationController* controller = &contents->GetController();
106 // 204 makes a redirect to the local NTP. 100 // 204 makes a redirect to the local NTP.
107 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 101 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
108 controller->GetLastCommittedEntry()->GetURL()); 102 contents->GetController().GetLastCommittedEntry()->GetURL());
109 } 103 }
110 104
111 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, FailedRequestInterception) { 105 IN_PROC_BROWSER_TEST_F(NewTabPageInterceptorTest, FailedRequestInterception) {
112 set_new_tab_url( 106 GURL new_tab_url =
113 net::URLRequestMockHTTPJob::GetMockHttpsUrl("notarealfile.html")); 107 net::URLRequestMockHTTPJob::GetMockHttpsUrl("notarealfile.html");
114 ChangeDefaultSearchProvider("notarealfile.html"); 108 ChangeDefaultSearchProvider("notarealfile.html");
115 109
116 ui_test_utils::NavigateToURL(browser(), new_tab_url()); 110 ui_test_utils::NavigateToURL(browser(), new_tab_url);
117 content::WebContents* contents = 111 content::WebContents* contents =
118 browser()->tab_strip_model()->GetWebContentsAt(0); 112 browser()->tab_strip_model()->GetWebContentsAt(0);
119 content::NavigationController* controller = &contents->GetController();
120 // Failed navigation makes a redirect to the local NTP. 113 // Failed navigation makes a redirect to the local NTP.
121 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 114 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
122 controller->GetLastCommittedEntry()->GetURL()); 115 contents->GetController().GetLastCommittedEntry()->GetURL());
123 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698