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 |