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

Side by Side Diff: chrome/browser/notifications/sync_notifier/welcome_delegate_unittest.cc

Issue 228753006: Reland r262272: "Hook up the Info URL from SyncedNotificationsAppInfo". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed test on linux+aura, disabled on linux-gtk Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/notifications/sync_notifier/welcome_delegate.cc ('k') | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/sync_notifier/welcome_delegate.h" 5 #include "chrome/browser/notifications/sync_notifier/welcome_delegate.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/notifications/desktop_notification_service.h" 9 #include "chrome/browser/notifications/desktop_notification_service.h"
9 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 10 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
11 #include "chrome/browser/notifications/message_center_notification_manager.h"
10 #include "chrome/browser/notifications/notification.h" 12 #include "chrome/browser/notifications/notification.h"
11 #include "chrome/browser/notifications/notification_test_util.h" 13 #include "chrome/browser/notifications/notification_test_util.h"
14 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/browser_with_test_window_test.h" 16 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "chrome/test/base/testing_browser_process.h" 17 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_profile_manager.h" 18 #include "chrome/test/base/testing_profile_manager.h"
19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/notification_service.h"
21 #include "content/public/test/test_utils.h"
22 #include "ui/message_center/fake_message_center_tray_delegate.h"
15 #include "ui/message_center/message_center.h" 23 #include "ui/message_center/message_center.h"
16 #include "ui/message_center/notifier_settings.h" 24 #include "ui/message_center/notifier_settings.h"
17 25
18 // TODO(dewittj): Port these tests to all platforms. 26 class WelcomeDelegateTest : public BrowserWithTestWindowTest {
19 #if defined(OS_CHROMEOS) 27 public:
20 #include "ash/test/ash_test_base.h" 28 WelcomeDelegateTest() {}
29 virtual ~WelcomeDelegateTest() {}
21 30
22 class WelcomeDelegateAshTest : public ash::test::AshTestBase { 31 virtual void SetUp() OVERRIDE {
23 public: 32 BrowserWithTestWindowTest::SetUp();
24 WelcomeDelegateAshTest() {} 33 #if !defined(OS_CHROMEOS)
25 virtual ~WelcomeDelegateAshTest() {} 34 message_center::MessageCenter::Initialize();
35 #endif
36 profile_manager_.reset(
37 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
38 ASSERT_TRUE(profile_manager_->SetUp());
26 39
27 virtual void SetUp() OVERRIDE { ash::test::AshTestBase::SetUp(); } 40 MessageCenterNotificationManager* manager =
41 static_cast<MessageCenterNotificationManager*>(
42 g_browser_process->notification_ui_manager());
43 manager->SetMessageCenterTrayDelegateForTest(
44 new message_center::FakeMessageCenterTrayDelegate(
45 message_center::MessageCenter::Get(), base::Closure()));
46 }
28 47
29 virtual void TearDown() OVERRIDE { ash::test::AshTestBase::TearDown(); } 48 virtual void TearDown() OVERRIDE {
49 g_browser_process->notification_ui_manager()->CancelAll();
50 profile_manager_.reset();
51 #if !defined(OS_CHROMEOS)
52 message_center::MessageCenter::Shutdown();
53 #endif
54 BrowserWithTestWindowTest::TearDown();
55 }
30 56
31 private: 57 private:
32 DISALLOW_COPY_AND_ASSIGN(WelcomeDelegateAshTest); 58 scoped_ptr<TestingProfileManager> profile_manager_;
59 DISALLOW_COPY_AND_ASSIGN(WelcomeDelegateTest);
33 }; 60 };
34 61
35 // Test that ensures a click removes the welcome notification. 62 #if defined(OS_LINUX) && !defined(USE_AURA)
36 TEST_F(WelcomeDelegateAshTest, ClickTest) { 63 #define MAYBE_ClickTest DISABLED_ClickTest
64 #else
65 #define MAYBE_ClickTest ClickTest
66 #endif
67
68 // Test that ensures a click removes the welcome notification. Also ensures
69 // navigation to the specified destination URL.
70 TEST_F(WelcomeDelegateTest, MAYBE_ClickTest) {
37 std::string id("foo"); 71 std::string id("foo");
38 TestingProfileManager profile_manager(TestingBrowserProcess::GetGlobal());
39 ASSERT_TRUE(profile_manager.SetUp());
40 72
41 TestingProfile test_profile;
42 message_center::NotifierId notifier_id( 73 message_center::NotifierId notifier_id(
43 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, 74 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
44 std::string("test")); 75 std::string("test"));
45 scoped_refptr<notifier::WelcomeDelegate> delegate( 76 scoped_refptr<notifier::WelcomeDelegate> delegate(
46 new notifier::WelcomeDelegate(id, &test_profile, notifier_id)); 77 new notifier::WelcomeDelegate(
78 id, profile(), notifier_id, GURL(kDefaultDestinationUrl)));
47 Notification notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT, 79 Notification notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
48 GURL("http://www.chromium.org"), 80 GURL("http://www.chromium.org"),
49 base::UTF8ToUTF16("title"), 81 base::UTF8ToUTF16("title"),
50 base::UTF8ToUTF16("body"), 82 base::UTF8ToUTF16("body"),
51 gfx::Image(), 83 gfx::Image(),
52 blink::WebTextDirectionDefault, 84 blink::WebTextDirectionDefault,
53 notifier_id, 85 notifier_id,
54 base::UTF8ToUTF16("display source"), 86 base::UTF8ToUTF16("display source"),
55 base::UTF8ToUTF16("Replace ID"), 87 base::UTF8ToUTF16("Replace ID"),
56 message_center::RichNotificationData(), 88 message_center::RichNotificationData(),
57 delegate.get()); 89 delegate.get());
58 g_browser_process->notification_ui_manager()->Add(notification, 90 g_browser_process->notification_ui_manager()->Add(notification, profile());
59 &test_profile);
60 EXPECT_TRUE(NULL != 91 EXPECT_TRUE(NULL !=
61 g_browser_process->notification_ui_manager()->FindById(id)); 92 g_browser_process->notification_ui_manager()->FindById(id));
93 EXPECT_TRUE(delegate->HasClickedListener());
94
95 // Set up an observer to wait for the navigation
96 content::WindowedNotificationObserver observer(
97 chrome::NOTIFICATION_TAB_ADDED,
98 content::NotificationService::AllSources());
99
62 delegate->Click(); 100 delegate->Click();
101
102 // Wait for navigation to finish.
103 observer.Wait();
104
105 // Verify the navigation happened as expected - we should be on chrome://flags
106 GURL url(kDefaultDestinationUrl);
107 content::WebContents* tab =
108 browser()->tab_strip_model()->GetActiveWebContents();
109 ASSERT_EQ(url, tab->GetController().GetActiveEntry()->GetVirtualURL());
110
63 EXPECT_TRUE(NULL == 111 EXPECT_TRUE(NULL ==
64 g_browser_process->notification_ui_manager()->FindById(id)); 112 g_browser_process->notification_ui_manager()->FindById(id));
65 } 113 }
66 114
115 #if defined(OS_LINUX) && !defined(USE_AURA)
116 #define MAYBE_ButtonClickTest DISABLED_ButtonClickTest
117 #else
118 #define MAYBE_ButtonClickTest ButtonClickTest
119 #endif
120
67 // Test that ensures the notifier is disabled when button is clicked. 121 // Test that ensures the notifier is disabled when button is clicked.
68 TEST_F(WelcomeDelegateAshTest, ButtonClickTest) { 122 TEST_F(WelcomeDelegateTest, MAYBE_ButtonClickTest) {
69 std::string id("foo"); 123 std::string id("foo");
70 TestingProfileManager profile_manager(TestingBrowserProcess::GetGlobal());
71 ASSERT_TRUE(profile_manager.SetUp());
72 124
73 TestingProfile test_profile;
74 message_center::NotifierId notifier_id( 125 message_center::NotifierId notifier_id(
75 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, 126 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
76 std::string("test")); 127 std::string("test"));
77 scoped_refptr<notifier::WelcomeDelegate> delegate( 128 scoped_refptr<notifier::WelcomeDelegate> delegate(
78 new notifier::WelcomeDelegate(id, &test_profile, notifier_id)); 129 new notifier::WelcomeDelegate(id, profile(), notifier_id, GURL()));
79 Notification notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT, 130 Notification notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
80 GURL("http://www.chromium.org"), 131 GURL("http://www.chromium.org"),
81 base::UTF8ToUTF16("title"), 132 base::UTF8ToUTF16("title"),
82 base::UTF8ToUTF16("body"), 133 base::UTF8ToUTF16("body"),
83 gfx::Image(), 134 gfx::Image(),
84 blink::WebTextDirectionDefault, 135 blink::WebTextDirectionDefault,
85 notifier_id, 136 notifier_id,
86 base::UTF8ToUTF16("display source"), 137 base::UTF8ToUTF16("display source"),
87 base::UTF8ToUTF16("Replace ID"), 138 base::UTF8ToUTF16("Replace ID"),
88 message_center::RichNotificationData(), 139 message_center::RichNotificationData(),
89 delegate.get()); 140 delegate.get());
90 141
91 // Add a notification with a WelcmeDelegate. 142 // Add a notification with a WelcmeDelegate.
92 g_browser_process->notification_ui_manager()->Add(notification, 143 g_browser_process->notification_ui_manager()->Add(notification, profile());
93 &test_profile);
94 // Expect it to be there. 144 // Expect it to be there.
95 EXPECT_TRUE(NULL != 145 EXPECT_TRUE(NULL !=
96 g_browser_process->notification_ui_manager()->FindById(id)); 146 g_browser_process->notification_ui_manager()->FindById(id));
97 147
98 // Set up the notification service. 148 // Set up the notification service.
99 DesktopNotificationService* notification_service = 149 DesktopNotificationService* notification_service =
100 DesktopNotificationServiceFactory::GetForProfile(&test_profile); 150 DesktopNotificationServiceFactory::GetForProfile(profile());
101 ASSERT_TRUE(NULL != notification_service); 151 ASSERT_TRUE(NULL != notification_service);
102 notification_service->SetNotifierEnabled(notifier_id, true); 152 notification_service->SetNotifierEnabled(notifier_id, true);
103 ASSERT_TRUE(notification_service->IsNotifierEnabled(notifier_id)); 153 ASSERT_TRUE(notification_service->IsNotifierEnabled(notifier_id));
104 154
105 // Click the button. 155 // Click the button.
106 delegate->ButtonClick(0); 156 delegate->ButtonClick(0);
107 157
108 // No more welcome toast. 158 // No more welcome toast.
109 EXPECT_TRUE(NULL == 159 EXPECT_TRUE(NULL ==
110 g_browser_process->notification_ui_manager()->FindById(id)); 160 g_browser_process->notification_ui_manager()->FindById(id));
111 // Expect the notifier to be disabled. 161 // Expect the notifier to be disabled.
112 EXPECT_FALSE(notification_service->IsNotifierEnabled(notifier_id)); 162 EXPECT_FALSE(notification_service->IsNotifierEnabled(notifier_id));
113 } 163 }
114
115 #endif // defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/notifications/sync_notifier/welcome_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698