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

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

Issue 2777813003: Fix mobile user agent string not being used when PlzNavigate is enabled. (Closed)
Patch Set: without PlzNavigate and with test 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
« no previous file with comments | « content/browser/frame_host/navigation_request.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/macros.h" 5 #include "base/macros.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/pattern.h" 7 #include "base/strings/pattern.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "content/browser/frame_host/navigation_entry_impl.h" 11 #include "content/browser/frame_host/navigation_entry_impl.h"
12 #include "content/browser/loader/resource_dispatcher_host_impl.h"
12 #include "content/browser/renderer_host/render_widget_host_impl.h" 13 #include "content/browser/renderer_host/render_widget_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h" 14 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/browser/web_contents/web_contents_view.h" 15 #include "content/browser/web_contents/web_contents_view.h"
15 #include "content/common/frame_messages.h" 16 #include "content/common/frame_messages.h"
16 #include "content/common/site_isolation_policy.h" 17 #include "content/common/site_isolation_policy.h"
17 #include "content/public/browser/javascript_dialog_manager.h" 18 #include "content/public/browser/javascript_dialog_manager.h"
18 #include "content/public/browser/load_notification_details.h" 19 #include "content/public/browser/load_notification_details.h"
19 #include "content/public/browser/navigation_controller.h" 20 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
25 #include "content/public/browser/resource_dispatcher_host.h" 26 #include "content/public/browser/resource_dispatcher_host.h"
26 #include "content/public/browser/web_contents_observer.h" 27 #include "content/public/browser/web_contents_observer.h"
27 #include "content/public/common/content_paths.h" 28 #include "content/public/common/content_paths.h"
28 #include "content/public/common/url_constants.h" 29 #include "content/public/common/url_constants.h"
29 #include "content/public/test/browser_test_utils.h" 30 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/content_browser_test.h" 31 #include "content/public/test/content_browser_test.h"
31 #include "content/public/test/content_browser_test_utils.h" 32 #include "content/public/test/content_browser_test_utils.h"
32 #include "content/public/test/test_navigation_observer.h" 33 #include "content/public/test/test_navigation_observer.h"
33 #include "content/public/test/test_utils.h" 34 #include "content/public/test/test_utils.h"
34 #include "content/shell/browser/shell.h" 35 #include "content/shell/browser/shell.h"
36 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
35 #include "content/test/content_browser_test_utils_internal.h" 37 #include "content/test/content_browser_test_utils_internal.h"
36 #include "net/dns/mock_host_resolver.h" 38 #include "net/dns/mock_host_resolver.h"
37 #include "net/test/embedded_test_server/embedded_test_server.h" 39 #include "net/test/embedded_test_server/embedded_test_server.h"
38 #include "testing/gmock/include/gmock/gmock.h" 40 #include "testing/gmock/include/gmock/gmock.h"
39 41
40 namespace content { 42 namespace content {
41 43
42 void ResizeWebContentsView(Shell* shell, const gfx::Size& size, 44 void ResizeWebContentsView(Shell* shell, const gfx::Size& size,
43 bool set_start_page) { 45 bool set_start_page) {
44 // Shell::SizeTo is not implemented on Aura; WebContentsView::SizeContents 46 // Shell::SizeTo is not implemented on Aura; WebContentsView::SizeContents
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 1405
1404 // Make sure the WebContents cleaned up the previous pending request. A new 1406 // Make sure the WebContents cleaned up the previous pending request. A new
1405 // request should be forwarded to the WebContentsDelegate. 1407 // request should be forwarded to the WebContentsDelegate.
1406 delegate.get()->request_to_lock_mouse_called_ = false; 1408 delegate.get()->request_to_lock_mouse_called_ = false;
1407 ASSERT_TRUE(ExecuteScript(shell(), 1409 ASSERT_TRUE(ExecuteScript(shell(),
1408 "window.domAutomationController.send(document.body." 1410 "window.domAutomationController.send(document.body."
1409 "requestPointerLock());")); 1411 "requestPointerLock());"));
1410 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_); 1412 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_);
1411 } 1413 }
1412 1414
1415 namespace {
1416 class TestResourceDispatcherHostDelegate
1417 : public ShellResourceDispatcherHostDelegate {
1418 public:
1419 explicit TestResourceDispatcherHostDelegate(bool* saw_override)
1420 : saw_override_(saw_override) {}
1421
1422 void RequestBeginning(
1423 net::URLRequest* request,
1424 ResourceContext* resource_context,
1425 AppCacheService* appcache_service,
1426 ResourceType resource_type,
1427 std::vector<std::unique_ptr<ResourceThrottle>>* throttles) override {
1428 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1429 ShellResourceDispatcherHostDelegate::RequestBeginning(
1430 request, resource_context, appcache_service, resource_type, throttles);
1431
1432 net::HttpRequestHeaders headers = request->extra_request_headers();
1433 std::string user_agent;
1434 CHECK(headers.GetHeader(net::HttpRequestHeaders::kUserAgent, &user_agent));
1435 if (user_agent.find("foo") != std::string::npos)
1436 *saw_override_ = true;
1437 }
1438
1439 private:
1440 bool* saw_override_;
1441 };
1442 } // namespace
1443
1444 // Checks that user agent override string is only used when it's overridden.
1445 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, UserAgentOverride) {
1446 bool saw_override = false;
1447 TestResourceDispatcherHostDelegate new_delegate(&saw_override);
1448 ResourceDispatcherHostDelegate* old_delegate =
1449 ResourceDispatcherHostImpl::Get()->delegate();
1450 BrowserThread::PostTask(
1451 BrowserThread::IO, FROM_HERE,
1452 base::Bind(&ResourceDispatcherHost::SetDelegate,
1453 base::Unretained(ResourceDispatcherHostImpl::Get()),
1454 &new_delegate));
1455
1456 ASSERT_TRUE(embedded_test_server()->Start());
1457 const GURL kUrl(embedded_test_server()->GetURL("/simple_page.html"));
1458 NavigateToURL(shell(), kUrl);
1459 ASSERT_FALSE(saw_override);
1460
1461 shell()->web_contents()->SetUserAgentOverride("foo");
1462 NavigateToURL(shell(), kUrl);
1463 ASSERT_FALSE(saw_override);
1464
1465 shell()
1466 ->web_contents()
1467 ->GetController()
1468 .GetActiveEntry()
nasko 2017/03/27 19:52:31 GetLastCommittedEntry(), GetActiveEntry is depreca
jam 2017/03/27 20:00:14 Done.
1469 ->SetIsOverridingUserAgent(true);
1470 TestNavigationObserver tab_observer(shell()->web_contents(), 1);
1471 shell()->web_contents()->GetController().Reload(ReloadType::NORMAL, false);
1472 tab_observer.Wait();
1473 ASSERT_TRUE(saw_override);
1474
1475 BrowserThread::PostTask(
1476 BrowserThread::IO, FROM_HERE,
1477 base::Bind(&ResourceDispatcherHost::SetDelegate,
1478 base::Unretained(ResourceDispatcherHostImpl::Get()),
1479 old_delegate));
1480 }
1481
1413 } // namespace content 1482 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698