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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_browsertest.cc

Issue 1310743003: Consistently use LoFi for an entire page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added test and rebased Created 5 years, 2 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 "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/download/download_manager_impl.h" 9 #include "content/browser/download/download_manager_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/resource_dispatcher_host.h" 13 #include "content/public/browser/resource_dispatcher_host.h"
14 #include "content/public/browser/resource_dispatcher_host_delegate.h" 14 #include "content/public/browser/resource_dispatcher_host_delegate.h"
15 #include "content/public/browser/resource_request_info.h" 15 #include "content/public/browser/resource_request_info.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
18 #include "content/public/test/browser_test_utils.h" 18 #include "content/public/test/browser_test_utils.h"
19 #include "content/public/test/content_browser_test.h" 19 #include "content/public/test/content_browser_test.h"
20 #include "content/public/test/content_browser_test_utils.h" 20 #include "content/public/test/content_browser_test_utils.h"
21 #include "content/public/test/test_navigation_observer.h"
21 #include "content/public/test/test_utils.h" 22 #include "content/public/test/test_utils.h"
22 #include "content/shell/browser/shell.h" 23 #include "content/shell/browser/shell.h"
23 #include "content/shell/browser/shell_content_browser_client.h" 24 #include "content/shell/browser/shell_content_browser_client.h"
24 #include "content/shell/browser/shell_network_delegate.h" 25 #include "content/shell/browser/shell_network_delegate.h"
25 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
26 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
27 #include "net/test/embedded_test_server/http_request.h" 28 #include "net/test/embedded_test_server/http_request.h"
28 #include "net/test/embedded_test_server/http_response.h" 29 #include "net/test/embedded_test_server/http_response.h"
29 #include "net/test/url_request/url_request_failed_job.h" 30 #include "net/test/url_request/url_request_failed_job.h"
30 #include "net/test/url_request/url_request_mock_http_job.h" 31 #include "net/test/url_request/url_request_mock_http_job.h"
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 520
520 NavigateToURLBlockUntilNavigationsComplete( 521 NavigateToURLBlockUntilNavigationsComplete(
521 shell(), 522 shell(),
522 embedded_test_server()->GetURL("/client_redirect.html"), 523 embedded_test_server()->GetURL("/client_redirect.html"),
523 2); 524 2);
524 525
525 EXPECT_TRUE( 526 EXPECT_TRUE(
526 delegate.page_transition() & ui::PAGE_TRANSITION_CLIENT_REDIRECT); 527 delegate.page_transition() & ui::PAGE_TRANSITION_CLIENT_REDIRECT);
527 } 528 }
528 529
530 class ShouldEnableLoFiModeResourceDispatcherHostDelegate
531 : public ResourceDispatcherHostDelegate {
mmenke 2015/10/08 19:06:09 This class seems very sensitive to receiving unexp
megjablon 2015/10/08 22:20:40 Done.
532 public:
533 ShouldEnableLoFiModeResourceDispatcherHostDelegate(GURL watch_url)
mmenke 2015/10/08 19:06:09 nit: const GURL&
megjablon 2015/10/08 22:20:40 Done.
534 : watch_url_(watch_url),
535 use_lofi_(false),
536 should_enable_lofi_mode_called_(false) {}
537
538 // ResourceDispatcherHostDelegate implementation:
539 void RequestBeginning(net::URLRequest* request,
540 ResourceContext* resource_context,
541 AppCacheService* appcache_service,
542 ResourceType resource_type,
543 ScopedVector<ResourceThrottle>* throttles) override {
544 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
545 EXPECT_EQ(use_lofi_, info->IsUsingLoFi());
546 }
547
548 bool ShouldEnableLoFiMode(
549 net::URLRequest* request,
550 content::ResourceContext* resource_context) override {
551 if (should_enable_lofi_mode_called_)
552 EXPECT_TRUE(false);
553 should_enable_lofi_mode_called_ = true;
554 EXPECT_EQ(watch_url_, request->url());
555 return use_lofi_;
556 }
557
558 void Reset(bool use_lofi) {
559 use_lofi_ = use_lofi;
560 should_enable_lofi_mode_called_ = false;
561 }
562
563 void SetWatchUrl(GURL watch_url) {
mmenke 2015/10/08 19:06:09 const GURL&
megjablon 2015/10/08 22:20:40 Done.
564 watch_url_ = watch_url;
565 }
566
567 bool should_enable_lofi_mode_called() {
568 return should_enable_lofi_mode_called_;
569 }
570
571 private:
572 GURL watch_url_;
573 bool use_lofi_;
574 bool should_enable_lofi_mode_called_;
575 };
576
577 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
578 ShouldEnableLoFiMode) {
579 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
580
581 ShouldEnableLoFiModeResourceDispatcherHostDelegate delegate(
582 embedded_test_server()->GetURL("/page_with_iframe.html"));
583 ResourceDispatcherHost::Get()->SetDelegate(&delegate);
mmenke 2015/10/08 19:06:09 Teardown also does seem threadsafe - we should res
mmenke 2015/10/08 19:06:09 Hrm...This doesn't seem threadsafe - the RDH lives
megjablon 2015/10/08 22:20:40 I'm not sure I follow. Why do we need to post a ta
mmenke 2015/10/08 22:25:15 Sorry, that was a typo - we're on the UI thread, w
megjablon 2015/10/08 23:39:07 Is this feasible? I'm just getting test failed wit
mmenke 2015/10/09 15:31:56 Tests that do that are just crossing their fingers
584
585 // Navigate with ShouldEnableLoFiMode true.
586 delegate.Reset(true);
587 NavigateToURLBlockUntilNavigationsComplete(
588 shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
589 EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
mmenke 2015/10/08 19:06:09 Each of these should be a separate test (the reloa
megjablon 2015/10/08 22:20:40 Done.
590
591 // Navigate with ShouldEnableLoFiMode false.
592 delegate.Reset(false);
593 NavigateToURLBlockUntilNavigationsComplete(
594 shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
595 EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
596
597 // Reload. ShouldEnableLoFiMode should be called.
598 delegate.Reset(true);
599 ReloadBlockUntilNavigationsComplete(shell(), 1);
600 EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
601
602 // Go to a different page.
603 delegate.Reset(false);
604 delegate.SetWatchUrl(embedded_test_server()->GetURL("/title1.html"));
605 NavigateToURLBlockUntilNavigationsComplete(
606 shell(), embedded_test_server()->GetURL("/title1.html"), 1);
607 EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
608
609 // Go back.
610 delegate.Reset(true);
611 delegate.SetWatchUrl(
612 embedded_test_server()->GetURL("/page_with_iframe.html"));
613 WaitForLoadStop(shell()->web_contents());
614 TestNavigationObserver tab_observer(shell()->web_contents(), 1);
615 shell()->GoBackOrForward(-1);
616 tab_observer.Wait();
617 EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
618
619
620 // Reload with Lo-Fi disabled.
621 delegate.Reset(false);
622 WaitForLoadStop(shell()->web_contents());
623 TestNavigationObserver tab_observer2(shell()->web_contents(), 1);
624 shell()->web_contents()->GetController().ReloadDisableLoFi(true);
625 tab_observer2.Wait();
626 EXPECT_FALSE(delegate.should_enable_lofi_mode_called());
627 }
628
529 } // namespace content 629 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/browser/loader/resource_dispatcher_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698