Index: chrome/browser/garbled_text_helper_unittest.cc |
diff --git a/chrome/browser/garbled_text_helper_unittest.cc b/chrome/browser/garbled_text_helper_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..756b6ce69f0099eea917a7c2ac8c5cbc3e5eb22c |
--- /dev/null |
+++ b/chrome/browser/garbled_text_helper_unittest.cc |
@@ -0,0 +1,92 @@ |
+// 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 "chrome/browser/garbled_text_helper.h" |
+#include "chrome/browser/garbled_text_infobar_delegate.h" |
+#include "chrome/browser/garbled_text_test_helper.h" |
+#include "chrome/browser/garbled_text_url_tracker.h" |
+#include "chrome/browser/infobars/infobar_tab_helper.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
+#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/test/test_browser_thread.h" |
+#include "googleurl/src/gurl.h" |
+ |
+class GarbledTextHelperTest : public TabContentsWrapperTestHarness { |
+ public: |
+ typedef GarbledTextURLTracker::GarbledURLs GarbledURLs; |
+ typedef GarbledTextURLTracker::Blacklist Blacklist; |
+ |
+ virtual void SetUp() OVERRIDE { |
+ TabContentsWrapperTestHarness::SetUp(); |
+ test_helper_.reset(new GarbledTextTestHelper( |
+ contents_wrapper()->profile())); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ test_helper_.reset(); |
+ TabContentsWrapperTestHarness::TearDown(); |
+ } |
+ |
+ protected: |
+ GarbledTextHelperTest() |
+ : ui_thread_(content::BrowserThread::UI, &message_loop_), |
+ io_thread_(content::BrowserThread::IO, &message_loop_) { |
+ } |
+ |
+ GarbledTextTestHelper* test_helper() { |
+ return test_helper_.get(); |
+ } |
+ |
+ virtual ~GarbledTextHelperTest() {} |
+ |
+ void OnGarbledTextDetected(const GarbledURLs& garbled_urls) { |
+ contents_wrapper()->garbled_text_helper()->OnGarbledTextDetected( |
+ garbled_urls); |
+ MessageLoop::current()->RunAllPending(); |
+ } |
+ |
+ GarbledTextInfoBarDelegate* garbled_text_infobar() { |
+ InfoBarTabHelper* infobar_helper = contents_wrapper()->infobar_tab_helper(); |
+ for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
+ GarbledTextInfoBarDelegate* result = infobar_helper-> |
+ GetInfoBarDelegateAt(i)->AsGarbledTextInfoBarDelegate(); |
+ if (result) |
+ return result; |
+ } |
+ return NULL; |
+ } |
+ |
+ void AcceptInfoBar(GarbledTextInfoBarDelegate* infobar) { |
+ infobar->Accept(); |
+ MessageLoop::current()->RunAllPending(); |
+ } |
+ |
+ const Blacklist& blacklist() { |
+ return test_helper()->tracker()->blacklist_; |
+ } |
+ |
+ private: |
+ content::TestBrowserThread ui_thread_; |
+ content::TestBrowserThread io_thread_; |
+ scoped_ptr<GarbledTextTestHelper> test_helper_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GarbledTextHelperTest); |
+}; |
+ |
+TEST_F(GarbledTextHelperTest, GarbledTextHandlingTest) { |
+ test_helper()->Initialize(); |
+ |
+ GarbledURLs garbled_urls; |
+ garbled_urls.push_back(GURL("http://foo.example.com/")); |
+ OnGarbledTextDetected(garbled_urls); |
+ |
+ GarbledTextInfoBarDelegate* infobar = garbled_text_infobar(); |
+ EXPECT_TRUE(infobar); |
+ AcceptInfoBar(infobar); |
+ |
+ EXPECT_EQ(1u, blacklist().size()); |
+ EXPECT_EQ("foo.example.com", *blacklist().begin()); |
+} |