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

Side by Side Diff: chrome/browser/extensions/extension_resource_request_policy_apitest.cc

Issue 2454563003: Fix web accessible resource checks in ShouldAllowOpenURL (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 #if defined(OS_MACOSX) 330 #if defined(OS_MACOSX)
331 #define MAYBE_ExtensionAccessibleResources DISABLED_ExtensionAccessibleResources 331 #define MAYBE_ExtensionAccessibleResources DISABLED_ExtensionAccessibleResources
332 #else 332 #else
333 #define MAYBE_ExtensionAccessibleResources ExtensionAccessibleResources 333 #define MAYBE_ExtensionAccessibleResources ExtensionAccessibleResources
334 #endif 334 #endif
335 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, 335 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest,
336 MAYBE_ExtensionAccessibleResources) { 336 MAYBE_ExtensionAccessibleResources) {
337 ASSERT_TRUE(RunExtensionSubtest("accessible_cer", "main.html")) << message_; 337 ASSERT_TRUE(RunExtensionSubtest("accessible_cer", "main.html")) << message_;
338 } 338 }
339 339
340 class NavigationErrorObserver : public content::WebContentsObserver {
341 public:
342 NavigationErrorObserver(content::WebContents* web_contents, const GURL& url)
343 : content::WebContentsObserver(web_contents),
344 url_(url),
345 saw_navigation_(false) {}
346
347 void DidFinishNavigation(content::NavigationHandle* handle) override {
348 if (handle->GetURL() != url_)
349 return;
350 EXPECT_TRUE(handle->IsErrorPage());
351 saw_navigation_ = true;
352 if (run_loop_.running())
353 run_loop_.Quit();
354 }
355
356 void Wait() {
357 if (!saw_navigation_)
358 run_loop_.Run();
359 }
360
361 private:
362 // The url we want to see a navigation for.
363 GURL url_;
364
365 // Have we seen the navigation for |url_| yet?
366 bool saw_navigation_;
367
368 base::RunLoop run_loop_;
369
370 DISALLOW_COPY_AND_ASSIGN(NavigationErrorObserver);
371 };
372
373 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, 340 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest,
374 IframeNavigateToInaccessible) { 341 IframeNavigateToInaccessible) {
375 ASSERT_TRUE(embedded_test_server()->Start()); 342 ASSERT_TRUE(embedded_test_server()->Start());
376 ASSERT_TRUE(LoadExtension( 343 ASSERT_TRUE(LoadExtension(
377 test_data_dir_.AppendASCII("extension_resource_request_policy") 344 test_data_dir_.AppendASCII("extension_resource_request_policy")
378 .AppendASCII("some_accessible"))); 345 .AppendASCII("some_accessible")));
379 346
380 GURL iframe_navigate_url(embedded_test_server()->GetURL( 347 GURL iframe_navigate_url(embedded_test_server()->GetURL(
381 "/extensions/api_test/extension_resource_request_policy/" 348 "/extensions/api_test/extension_resource_request_policy/"
382 "iframe_navigate.html")); 349 "iframe_navigate.html"));
383 350
384 ui_test_utils::NavigateToURL(browser(), iframe_navigate_url); 351 ui_test_utils::NavigateToURL(browser(), iframe_navigate_url);
385 352
386 content::WebContents* web_contents = 353 content::WebContents* web_contents =
387 browser()->tab_strip_model()->GetActiveWebContents(); 354 browser()->tab_strip_model()->GetActiveWebContents();
388 355
389 GURL private_page( 356 GURL private_page(
390 "chrome-extension://kegmjfcnjamahdnldjmlpachmpielcdk/private.html"); 357 "chrome-extension://kegmjfcnjamahdnldjmlpachmpielcdk/private.html");
391 NavigationErrorObserver observer(web_contents, private_page);
392 ASSERT_TRUE(content::ExecuteScript(web_contents, "navigateFrameNow()")); 358 ASSERT_TRUE(content::ExecuteScript(web_contents, "navigateFrameNow()"));
393 observer.Wait(); 359 WaitForLoadStop(web_contents);
360 EXPECT_NE(private_page, web_contents->GetLastCommittedURL());
361 std::string content;
362 EXPECT_TRUE(ExecuteScriptAndExtractString(
363 ChildFrameAt(web_contents->GetMainFrame(), 0),
364 "domAutomationController.send(document.body.innerText)", &content));
365 EXPECT_NE("Private", content);
Devlin 2016/11/02 16:19:22 It looks like the previous version of this checked
alexmos 2016/11/02 17:32:46 I removed the error page expectation because there
Devlin 2016/11/02 20:50:57 Two thoughts: - Is there any way we can test that
alexmos 2016/11/03 00:43:26 Unfortunately, this is tricky. The result depends
Devlin 2016/11/03 00:57:09 Okay, this is fine for now, thanks for the TODO.
394 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698