Chromium Code Reviews| Index: chrome/browser/notifications/desktop_notification_service_unittest.cc |
| 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 0000000000000000000000000000000000000000..27ceb8cf98754a62beae357ee9b0cf2d910c1e5f |
| --- /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, |
|
bulach
2010/07/05 09:54:54
shouldn't this post to IO? also, perhaps DCHECK on
Nico
2010/07/05 15:50:14
Yes: http://src.chromium.org/viewvc/chrome?view=re
|
| + 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()); |
| +} |
| + |
| + |