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

Unified Diff: chrome/browser/garbled_text_service_unittest.cc

Issue 9235004: [Garbled Text][Infobar] Adding infobar to suggest turning on encoding detection. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 8 years, 11 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
« no previous file with comments | « chrome/browser/garbled_text_service.cc ('k') | chrome/browser/garbled_text_test_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/garbled_text_service_unittest.cc
diff --git a/chrome/browser/garbled_text_service_unittest.cc b/chrome/browser/garbled_text_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c62d5f4e9ec35bdbeac9d0ee3a3401cae63282d5
--- /dev/null
+++ b/chrome/browser/garbled_text_service_unittest.cc
@@ -0,0 +1,137 @@
+// 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_service.h"
+
+#include "base/message_loop.h"
+#include "chrome/browser/garbled_text_test_helper.h"
+#include "chrome/browser/prefs/pref_member.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_profile.h"
+#include "content/test/test_browser_thread.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+void OnCompleted(bool* completed) {
+ *completed = true;
+}
+
+} // anonymous namespace
+
+class GarbledTextServiceTest : public ::testing::Test {
+ public:
+ GarbledTextServiceTest()
+ : ui_thread_(content::BrowserThread::UI, &message_loop_),
+ io_thread_(content::BrowserThread::IO, &message_loop_) {}
+
+ typedef GarbledTextURLTracker::Blacklist Blacklist;
+
+ virtual void SetUp() OVERRIDE {
+ test_helper_.reset(new GarbledTextTestHelper(profile()));
+ }
+
+ virtual void TearDown() OVERRIDE {
+ message_loop_.RunAllPending();
+ }
+
+ protected:
+ Profile* profile() {
+ return &profile_;
+ }
+
+ GarbledTextService* service() {
+ return test_helper_->service();
+ }
+
+ GarbledTextURLTracker* tracker() {
+ return test_helper_->tracker();
+ }
+
+ const Blacklist& blacklist() {
+ return tracker()->blacklist_;
+ }
+
+ void UpdateBlacklist(const GarbledTextURLTracker::GarbledURLs& urls) {
+ bool completed = false;
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&GarbledTextService::UpdateBlacklist,
+ service()->AsWeakPtr(), urls,
+ base::Bind(&OnCompleted, &completed)));
+ message_loop_.RunAllPending();
+ EXPECT_TRUE(completed);
+ }
+
+ GarbledTextTestHelper* test_helper() {
+ return test_helper_.get();
+ }
+
+ private:
+ MessageLoop message_loop_;
+ content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread io_thread_;
+
+ TestingProfile profile_;
+ scoped_ptr<GarbledTextTestHelper> test_helper_;
+
+ DISALLOW_COPY_AND_ASSIGN(GarbledTextServiceTest);
+};
+
+TEST_F(GarbledTextServiceTest, LoadAndUpdateTest) {
+ const std::string kHost1("foo.example.com");
+ const std::string kHost2("bar.example.com");
+
+ {
+ PrefService* prefs = profile()->GetPrefs();
+ EXPECT_TRUE(prefs);
+ GarbledTextServiceFactory::GetInstance()->RegisterUserPrefs(prefs);
+ ListPrefUpdate update(prefs, GarbledTextService::kPrefGarbledTextBlacklist);
+ ListValue* blacklist = update.Get();
+ EXPECT_TRUE(blacklist);
+
+ blacklist->Append(base::Value::CreateStringValue("foo.example.com"));
+ }
+
+ test_helper()->Initialize();
+
+ EXPECT_EQ(1u, blacklist().size());
+ EXPECT_TRUE(blacklist().find(kHost1) != blacklist().end());
+
+ GURL kGarbledURLs[] = {
+ GURL("http://foo.example.com/"),
+ GURL("http://bar.example.com/"),
+ };
+ GarbledTextURLTracker::GarbledURLs urls(
+ kGarbledURLs, kGarbledURLs + arraysize(kGarbledURLs));
+
+ test_helper()->enabled()->SetValue(false);
+ UpdateBlacklist(urls);
+ EXPECT_EQ(1u, blacklist().size());
+ EXPECT_TRUE(blacklist().find(kHost1) != blacklist().end());
+
+ test_helper()->enabled()->SetValue(true);
+ UpdateBlacklist(urls);
+ EXPECT_EQ(2u, blacklist().size());
+ EXPECT_TRUE(blacklist().find(kHost1) != blacklist().end());
+ EXPECT_TRUE(blacklist().find(kHost2) != blacklist().end());
+
+ PrefService* prefs = profile()->GetPrefs();
+ EXPECT_TRUE(prefs);
+ const ListValue* pref_blacklist = prefs->GetList(
+ GarbledTextService::kPrefGarbledTextBlacklist);
+ EXPECT_TRUE(pref_blacklist);
+ EXPECT_EQ(2u, pref_blacklist->GetSize());
+
+ std::string entry;
+ EXPECT_TRUE(pref_blacklist->GetString(0, &entry));
+ EXPECT_EQ("foo.example.com", entry);
+
+ entry.clear();
+ EXPECT_TRUE(pref_blacklist->GetString(1, &entry));
+ EXPECT_EQ("bar.example.com", entry);
+}
« no previous file with comments | « chrome/browser/garbled_text_service.cc ('k') | chrome/browser/garbled_text_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698