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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/resource_dispatcher_host_browsertest.cc
diff --git a/content/browser/loader/resource_dispatcher_host_browsertest.cc b/content/browser/loader/resource_dispatcher_host_browsertest.cc
index b612d302df5e85ae96088109474302b5df7708d8..197d2e9739de59cbcae43e4a72e3626d072b0706 100644
--- a/content/browser/loader/resource_dispatcher_host_browsertest.cc
+++ b/content/browser/loader/resource_dispatcher_host_browsertest.cc
@@ -18,6 +18,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
+#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_content_browser_client.h"
@@ -526,4 +527,103 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
delegate.page_transition() & ui::PAGE_TRANSITION_CLIENT_REDIRECT);
}
+class ShouldEnableLoFiModeResourceDispatcherHostDelegate
+ : 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.
+ public:
+ ShouldEnableLoFiModeResourceDispatcherHostDelegate(GURL watch_url)
mmenke 2015/10/08 19:06:09 nit: const GURL&
megjablon 2015/10/08 22:20:40 Done.
+ : watch_url_(watch_url),
+ use_lofi_(false),
+ should_enable_lofi_mode_called_(false) {}
+
+ // ResourceDispatcherHostDelegate implementation:
+ void RequestBeginning(net::URLRequest* request,
+ ResourceContext* resource_context,
+ AppCacheService* appcache_service,
+ ResourceType resource_type,
+ ScopedVector<ResourceThrottle>* throttles) override {
+ const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
+ EXPECT_EQ(use_lofi_, info->IsUsingLoFi());
+ }
+
+ bool ShouldEnableLoFiMode(
+ net::URLRequest* request,
+ content::ResourceContext* resource_context) override {
+ if (should_enable_lofi_mode_called_)
+ EXPECT_TRUE(false);
+ should_enable_lofi_mode_called_ = true;
+ EXPECT_EQ(watch_url_, request->url());
+ return use_lofi_;
+ }
+
+ void Reset(bool use_lofi) {
+ use_lofi_ = use_lofi;
+ should_enable_lofi_mode_called_ = false;
+ }
+
+ void SetWatchUrl(GURL watch_url) {
mmenke 2015/10/08 19:06:09 const GURL&
megjablon 2015/10/08 22:20:40 Done.
+ watch_url_ = watch_url;
+ }
+
+ bool should_enable_lofi_mode_called() {
+ return should_enable_lofi_mode_called_;
+ }
+
+ private:
+ GURL watch_url_;
+ bool use_lofi_;
+ bool should_enable_lofi_mode_called_;
+};
+
+IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
+ ShouldEnableLoFiMode) {
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+
+ ShouldEnableLoFiModeResourceDispatcherHostDelegate delegate(
+ embedded_test_server()->GetURL("/page_with_iframe.html"));
+ 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
+
+ // Navigate with ShouldEnableLoFiMode true.
+ delegate.Reset(true);
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
+ 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.
+
+ // Navigate with ShouldEnableLoFiMode false.
+ delegate.Reset(false);
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
+ EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
+
+ // Reload. ShouldEnableLoFiMode should be called.
+ delegate.Reset(true);
+ ReloadBlockUntilNavigationsComplete(shell(), 1);
+ EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
+
+ // Go to a different page.
+ delegate.Reset(false);
+ delegate.SetWatchUrl(embedded_test_server()->GetURL("/title1.html"));
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/title1.html"), 1);
+ EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
+
+ // Go back.
+ delegate.Reset(true);
+ delegate.SetWatchUrl(
+ embedded_test_server()->GetURL("/page_with_iframe.html"));
+ WaitForLoadStop(shell()->web_contents());
+ TestNavigationObserver tab_observer(shell()->web_contents(), 1);
+ shell()->GoBackOrForward(-1);
+ tab_observer.Wait();
+ EXPECT_TRUE(delegate.should_enable_lofi_mode_called());
+
+
+ // Reload with Lo-Fi disabled.
+ delegate.Reset(false);
+ WaitForLoadStop(shell()->web_contents());
+ TestNavigationObserver tab_observer2(shell()->web_contents(), 1);
+ shell()->web_contents()->GetController().ReloadDisableLoFi(true);
+ tab_observer2.Wait();
+ EXPECT_FALSE(delegate.should_enable_lofi_mode_called());
+}
+
} // namespace content
« 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