Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager_unittest.cc |
diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager_unittest.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1179e13ee06447c01215b19f4e849a2a3ae577c2 |
--- /dev/null |
+++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager_unittest.cc |
@@ -0,0 +1,164 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h" |
+ |
+#include "base/bind.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/run_loop.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "net/url_request/url_request.h" |
+#include "net/url_request/url_request_test_util.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace data_reduction_proxy { |
+ |
+namespace { |
+ |
+enum State { |
+ NOT_CALLED, |
+ PROCEED, |
+ DONT_PROCEED, |
+}; |
+ |
+} // namespace |
+ |
+class TestDataReductionProxyUIManager : public DataReductionProxyUIManager { |
+ public: |
+ TestDataReductionProxyUIManager( |
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
+ : DataReductionProxyUIManager(ui_task_runner, io_task_runner) { |
+ } |
+ |
+ ~TestDataReductionProxyUIManager() override { |
+ } |
+ |
+ bool IsTabClosed(const BypassResource& resource) const override { |
+ return is_tab_closed_return_value_; |
+ } |
+ |
+ bool is_tab_closed_return_value_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TestDataReductionProxyUIManager); |
+}; |
+ |
+class DataReductionProxyUIManagerTest |
+ : public testing::Test { |
+ public: |
+ DataReductionProxyUIManagerTest() |
+ : state_ (NOT_CALLED), |
bengr
2014/12/31 01:10:21
remove space.
megjablon
2014/12/31 02:12:29
Done.
|
+ request_(context_.CreateRequest(GURL(), net::IDLE, &delegate_, NULL)) { |
+ ui_manager_ = new TestDataReductionProxyUIManager( |
+ content::BrowserThread::GetMessageLoopProxyForThread( |
+ content::BrowserThread::UI), |
+ content::BrowserThread::GetMessageLoopProxyForThread( |
+ content::BrowserThread::UI)); |
+ } |
+ |
+ void OnBlockingPageDoneCallback(bool proceed) { |
+ if (proceed) |
+ state_ = PROCEED; |
+ else |
+ state_ = DONT_PROCEED; |
+ } |
+ |
+ void ResetState() { |
+ state_ = NOT_CALLED; |
+ } |
+ |
+ protected: |
+ State state_; |
+ |
+ content::TestBrowserThreadBundle thread_bundle_; |
+ net::TestURLRequestContext context_; |
+ net::TestDelegate delegate_; |
+ |
+ scoped_ptr<net::URLRequest> request_; |
+ scoped_refptr<TestDataReductionProxyUIManager> ui_manager_; |
+}; |
+ |
+// Tests that the page is loaded after selecting continue on the blocking page |
+// and within the five minute window when the warning is not displayed again. |
+TEST_F(DataReductionProxyUIManagerTest, DisplayBlockingPage) { |
+ DataReductionProxyUIManager::BypassResource resource; |
+ resource.is_subresource = false; |
+ resource.callback = base::Bind( |
+ &DataReductionProxyUIManagerTest::OnBlockingPageDoneCallback, |
+ base::Unretained(this)); |
+ resource.render_process_host_id = 0; |
+ resource.render_view_id = 0; |
+ |
+ ui_manager_->is_tab_closed_return_value_ = false; |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DataReductionProxyUIManager::DisplayBlockingPage, |
+ ui_manager_, resource)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(PROCEED, state_); |
+ |
+ // The warning was ignored so for the next five minutes automatically continue |
+ // to the page. |
+ ResetState(); |
+ |
+ // This value does not matter since it will not be reached. If it is reached |
+ // the state will be DONT_PROCEED. |
+ ui_manager_->is_tab_closed_return_value_ = false; |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DataReductionProxyUIManager::DisplayBlockingPage, |
+ ui_manager_, resource)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(PROCEED, state_); |
+} |
+ |
+// Tests that the blocking page is not shown when the tab is already closed. |
+TEST_F(DataReductionProxyUIManagerTest, DontDisplayBlockingPage) { |
+ DataReductionProxyUIManager::BypassResource resource; |
+ resource.is_subresource = false; |
+ resource.callback = base::Bind( |
+ &DataReductionProxyUIManagerTest::OnBlockingPageDoneCallback, |
+ base::Unretained(this)); |
+ resource.render_process_host_id = 0; |
+ resource.render_view_id = 0; |
+ |
+ ui_manager_->is_tab_closed_return_value_ = true; |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DataReductionProxyUIManager::DisplayBlockingPage, |
+ ui_manager_, resource)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(DONT_PROCEED, state_); |
+} |
+ |
+// Tests that OnBlockingPageDone calls the callback of the resource. |
+TEST_F(DataReductionProxyUIManagerTest, OnBlockingPageDone) { |
+ DataReductionProxyUIManager::BypassResource resource; |
+ resource.is_subresource = false; |
+ resource.callback = base::Bind( |
+ &DataReductionProxyUIManagerTest::OnBlockingPageDoneCallback, |
+ base::Unretained(this)); |
+ resource.render_process_host_id = 0; |
+ resource.render_view_id = 0; |
+ |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, |
+ ui_manager_, resource, false)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(DONT_PROCEED, state_); |
+ |
+ ResetState(); |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, |
+ ui_manager_, resource, true)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(PROCEED, state_); |
+} |
+ |
+} // namespace data_reduction_proxy |