OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/notifications/desktop_notification_service.h" | |
6 | |
7 #include "base/task.h" | |
8 #include "base/waitable_event.h" | |
9 #include "chrome/browser/notifications/notifications_prefs_cache.h" | |
10 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | |
11 #include "chrome/test/testing_profile.h" | |
12 #include "grit/generated_resources.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 class DesktopNotificationServiceTest : public RenderViewHostTestHarness { | |
16 public: | |
17 DesktopNotificationServiceTest() | |
18 : event_(false, false), | |
19 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | |
20 } | |
21 | |
22 void LetIOThreadWait() { | |
23 event_.Wait(); | |
24 } | |
25 | |
26 base::WaitableEvent event_; | |
27 ScopedRunnableMethodFactory<DesktopNotificationServiceTest> method_factory_; | |
28 }; | |
29 | |
30 TEST_F(DesktopNotificationServiceTest, DefaultContentSettingSentToCache) { | |
31 // The current message loop was already initalized by the superclass. | |
32 ChromeThread ui_thread(ChromeThread::UI, MessageLoop::current()); | |
33 | |
34 // Create IO thread, start its message loop. | |
35 ChromeThread io_thread(ChromeThread::IO); | |
36 io_thread.Start(); | |
37 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
| |
38 method_factory_.NewRunnableMethod( | |
39 &DesktopNotificationServiceTest::LetIOThreadWait)); | |
40 | |
41 // Creates the service, calls InitPrefs() on it which loads data from the | |
42 // profile into the cache and then puts the cache in io thread mode. | |
43 DesktopNotificationService* service = | |
44 profile()->GetDesktopNotificationService(); | |
45 NotificationsPrefsCache* cache = service->prefs_cache(); | |
46 | |
47 // The default pref registered in DesktopNotificationService is "ask", | |
48 // and that's what sent to the cache. | |
49 EXPECT_EQ(CONTENT_SETTING_ASK, cache->CachedDefaultContentSetting()); | |
50 | |
51 // Change the default content setting. This will post a task on the IO thread | |
52 // to update the cache. | |
53 service->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | |
54 | |
55 // The updated pref shouldn't be sent to the cache immediately. | |
56 EXPECT_EQ(CONTENT_SETTING_ASK, cache->CachedDefaultContentSetting()); | |
57 | |
58 // Run IO thread tasks. | |
59 event_.Signal(); | |
60 io_thread.Stop(); | |
61 | |
62 // Now that IO thread events have been processed, it should be there. | |
63 EXPECT_EQ(CONTENT_SETTING_BLOCK, cache->CachedDefaultContentSetting()); | |
64 } | |
65 | |
66 | |
OLD | NEW |