summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/desktop_notification_service_unittest.cc
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-03 02:29:52 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-03 02:29:52 +0000
commit78dcb900b1ae1209d87cd746c1ff7d4c13f9f04e (patch)
tree716fc33ee1e0c300f6b56e5921c7b183258458d3 /chrome/browser/notifications/desktop_notification_service_unittest.cc
parent1350815259420160cfd2bdf8d94fbf9f80bc379b (diff)
downloadchromium_src-78dcb900b1ae1209d87cd746c1ff7d4c13f9f04e.zip
chromium_src-78dcb900b1ae1209d87cd746c1ff7d4c13f9f04e.tar.gz
chromium_src-78dcb900b1ae1209d87cd746c1ff7d4c13f9f04e.tar.bz2
Add a default content setting to the notifications service.
Not yet used anywhere, no behavior change. BUG=45547 TEST=none (unit tests) Review URL: http://codereview.chromium.org/2842043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51587 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications/desktop_notification_service_unittest.cc')
-rw-r--r--chrome/browser/notifications/desktop_notification_service_unittest.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc
new file mode 100644
index 0000000..27ceb8c
--- /dev/null
+++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc
@@ -0,0 +1,66 @@
+// 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 "chrome/browser/notifications/desktop_notification_service.h"
+
+#include "base/task.h"
+#include "base/waitable_event.h"
+#include "chrome/browser/notifications/notifications_prefs_cache.h"
+#include "chrome/browser/renderer_host/test/test_render_view_host.h"
+#include "chrome/test/testing_profile.h"
+#include "grit/generated_resources.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class DesktopNotificationServiceTest : public RenderViewHostTestHarness {
+ public:
+ DesktopNotificationServiceTest()
+ : event_(false, false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ }
+
+ void LetIOThreadWait() {
+ event_.Wait();
+ }
+
+ base::WaitableEvent event_;
+ ScopedRunnableMethodFactory<DesktopNotificationServiceTest> method_factory_;
+};
+
+TEST_F(DesktopNotificationServiceTest, DefaultContentSettingSentToCache) {
+ // The current message loop was already initalized by the superclass.
+ ChromeThread ui_thread(ChromeThread::UI, MessageLoop::current());
+
+ // Create IO thread, start its message loop.
+ ChromeThread io_thread(ChromeThread::IO);
+ io_thread.Start();
+ ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &DesktopNotificationServiceTest::LetIOThreadWait));
+
+ // Creates the service, calls InitPrefs() on it which loads data from the
+ // profile into the cache and then puts the cache in io thread mode.
+ DesktopNotificationService* service =
+ profile()->GetDesktopNotificationService();
+ NotificationsPrefsCache* cache = service->prefs_cache();
+
+ // The default pref registered in DesktopNotificationService is "ask",
+ // and that's what sent to the cache.
+ EXPECT_EQ(CONTENT_SETTING_ASK, cache->CachedDefaultContentSetting());
+
+ // Change the default content setting. This will post a task on the IO thread
+ // to update the cache.
+ service->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
+
+ // The updated pref shouldn't be sent to the cache immediately.
+ EXPECT_EQ(CONTENT_SETTING_ASK, cache->CachedDefaultContentSetting());
+
+ // Run IO thread tasks.
+ event_.Signal();
+ io_thread.Stop();
+
+ // Now that IO thread events have been processed, it should be there.
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, cache->CachedDefaultContentSetting());
+}
+
+