summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_resource
diff options
context:
space:
mode:
authormirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-23 23:27:53 +0000
committermirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-23 23:27:53 +0000
commitce5e69e294c5b9c9ae21746c37719bea7f28bf1e (patch)
treee47f4f065a038414527167ba379367ae2911e159 /chrome/browser/web_resource
parent145d22229a434580485e7059cf97f2fd5b6f5242 (diff)
downloadchromium_src-ce5e69e294c5b9c9ae21746c37719bea7f28bf1e.zip
chromium_src-ce5e69e294c5b9c9ae21746c37719bea7f28bf1e.tar.gz
chromium_src-ce5e69e294c5b9c9ae21746c37719bea7f28bf1e.tar.bz2
Add a unit test for web resource logo unpacking.
BUG=none TEST=new unit test should pass. Review URL: http://codereview.chromium.org/3473013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource')
-rw-r--r--chrome/browser/web_resource/web_resource_service_unittest.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/chrome/browser/web_resource/web_resource_service_unittest.cc b/chrome/browser/web_resource/web_resource_service_unittest.cc
new file mode 100644
index 0000000..1f2570c
--- /dev/null
+++ b/chrome/browser/web_resource/web_resource_service_unittest.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2010 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/json/json_reader.h"
+#include "base/time.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/web_resource/web_resource_service.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+typedef testing::Test WebResourceServiceTest;
+
+// Verifies that custom dates read from a web resource server are written to
+// the preferences file.
+TEST_F(WebResourceServiceTest, UnpackLogoSignal) {
+ // Set up a testing profile and create a web resource service.
+ TestingProfile profile;
+ scoped_refptr<WebResourceService> web_resource_service(
+ new WebResourceService(&profile));
+
+ // Set up start and end dates in a Dictionary as if parsed from the service.
+ std::string json = "{ "
+ " \"topic\": {"
+ " \"answers\": ["
+ " {"
+ " \"custom_logo_start\": \"31/01/10 01:00 GMT\","
+ " \"custom_logo_end\": \"31/01/12 01:00 GMT\""
+ " }"
+ " ]"
+ " }"
+ "}";
+ scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>(
+ base::JSONReader::Read(json, false)));
+
+ // Check that prefs are set correctly.
+ web_resource_service->UnpackLogoSignal(*(test_json.get()));
+ double logo_start =
+ profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoStart);
+ ASSERT_EQ(logo_start, 1264899600); // unix epoch for Jan 31 2010 0100 GMT.
+ double logo_end =
+ profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoEnd);
+ ASSERT_EQ(logo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT.
+
+ // Change the start only and recheck.
+ json = "{ "
+ " \"topic\": {"
+ " \"answers\": ["
+ " {"
+ " \"custom_logo_start\": \"28/02/10 14:00 GMT\","
+ " \"custom_logo_end\": \"31/01/12 01:00 GMT\""
+ " }"
+ " ]"
+ " }"
+ "}";
+ test_json->Clear();
+ test_json.reset(static_cast<DictionaryValue*>(
+ base::JSONReader::Read(json, false)));
+
+ // Check that prefs are set correctly.
+ web_resource_service->UnpackLogoSignal(*(test_json.get()));
+ logo_start = profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoStart);
+ ASSERT_EQ(logo_start, 1267365600); // date changes to Feb 28 2010 1400 GMT.
+
+ // If no date is included in the prefs, reset custom logo dates to 0.
+ json = "{ "
+ " \"topic\": {"
+ " \"answers\": ["
+ " {"
+ " }"
+ " ]"
+ " }"
+ "}";
+ test_json->Clear();
+ test_json.reset(static_cast<DictionaryValue*>(
+ base::JSONReader::Read(json, false)));
+
+ // Check that prefs are set correctly.
+ web_resource_service->UnpackLogoSignal(*(test_json.get()));
+ logo_start = profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoStart);
+ ASSERT_EQ(logo_start, 0); // date value reset to 0;
+ logo_end = profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoEnd);
+ ASSERT_EQ(logo_end, 0); // date value reset to 0;
+}
+