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

Side by Side Diff: chrome/browser/notifications/desktop_notification_service_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698