Index: chrome/browser/garbled_text_browsertest.cc |
diff --git a/chrome/browser/garbled_text_browsertest.cc b/chrome/browser/garbled_text_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3ee085aa9a9e801dc1b588c8b815b001b7b0de94 |
--- /dev/null |
+++ b/chrome/browser/garbled_text_browsertest.cc |
@@ -0,0 +1,128 @@ |
+// Copyright (c) 2012 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 "base/bind.h" |
+#include "base/message_loop.h" |
+#include "chrome/browser/garbled_text_helper.h" |
+#include "chrome/browser/garbled_text_infobar_delegate.h" |
+#include "chrome/browser/garbled_text_service.h" |
+#include "chrome/browser/garbled_text_url_tracker.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/renderer_host/dummy_resource_dispatcher_host_delegate.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
+#include "chrome/test/base/in_process_browser_test.h" |
+#include "chrome/test/base/ui_test_utils.h" |
+#include "content/browser/renderer_host/resource_dispatcher_host.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/common/resource_response.h" |
+#include "content/test/test_browser_thread.h" |
+#include "googleurl/src/gurl.h" |
+ |
+namespace { |
+ |
+void Nop() {} |
+ |
+class TestingRDHDelegate : public DummyResourceDispatcherHostDelegate { |
+ public: |
+ TestingRDHDelegate(ResourceDispatcherHost* rdh, |
+ const GURL& url) |
+ : DummyResourceDispatcherHostDelegate(rdh->delegate()), |
+ rdh_(rdh), |
+ url_(url), |
+ completed_(false), |
+ needs_encoding_detection_(false) { |
+ rdh_->set_delegate(this); |
+ } |
+ |
+ virtual ~TestingRDHDelegate() { |
+ DCHECK_EQ(this, rdh_->delegate()); |
+ rdh_->set_delegate(underlying()); |
+ } |
+ |
+ virtual void OnResponseStarted( |
+ net::URLRequest* request, |
+ content::ResourceResponse* response, |
+ ResourceMessageFilter* filter) OVERRIDE { |
+ DummyResourceDispatcherHostDelegate::OnResponseStarted( |
+ request, response, filter); |
+ if (request->url() == url_) { |
+ completed_ = true; |
+ needs_encoding_detection_ = response->needs_encoding_detection; |
+ } |
+ } |
+ |
+ void reset(GURL url) { |
+ url_ = url; |
+ completed_ = false; |
+ needs_encoding_detection_ = false; |
+ } |
+ |
+ bool completed() const { |
+ return completed_; |
+ } |
+ |
+ bool needs_encoding_detection() const { |
+ return needs_encoding_detection_; |
+ } |
+ |
+ private: |
+ ResourceDispatcherHost* rdh_; |
+ GURL url_; |
+ bool completed_; |
+ bool needs_encoding_detection_; |
+}; |
+ |
+} // anonymous namespace |
+ |
+class GarbledTextBrowserTest : public InProcessBrowserTest { |
+ public: |
+ typedef GarbledTextURLTracker::GarbledURLs GarbledURLs; |
+ |
+ protected: |
+ GarbledTextBrowserTest() {} |
+ ~GarbledTextBrowserTest() {} |
+ |
+ void UpdateBlacklist(const GURL& url) { |
+ if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&GarbledTextBrowserTest::UpdateBlacklist, |
+ base::Unretained(this), url)); |
+ ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
+ return; |
+ } |
+ |
+ GarbledURLs urls(&url, &url+1); |
+ GarbledTextService* service = GarbledTextServiceFactory::GetInstance()-> |
+ GetForProfile(browser()->profile()); |
+ service->UpdateBlacklist(urls, base::Bind(&Nop)); |
+ ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::IO); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(GarbledTextBrowserTest); |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(GarbledTextBrowserTest, LoadTimeMarkingTest) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ GURL url(test_server()->GetURL("files/garbled_text/foo.html")); |
+ TestingRDHDelegate delegate(ResourceDispatcherHost::Get(), |
+ url); |
+ |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ EXPECT_TRUE(delegate.completed()); |
+ EXPECT_FALSE(delegate.needs_encoding_detection()); |
+ |
+ UpdateBlacklist(url); |
+ |
+ delegate.reset(url); |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ EXPECT_TRUE(delegate.completed()); |
+ EXPECT_TRUE(delegate.needs_encoding_detection()); |
+ |
+ test_server()->Stop(); |
+} |