Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/Notification.cpp

Issue 29539858: Issue 5506 - Make the notification test work. (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Removed dead code from previous patch Created Sept. 12, 2017, 3:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
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 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return; 73 return;
74 } 74 }
75 ServerResponse serverResponse; 75 ServerResponse serverResponse;
76 serverResponse.status = IWebRequest::NS_OK; 76 serverResponse.status = IWebRequest::NS_OK;
77 serverResponse.responseStatus = 200; 77 serverResponse.responseStatus = 200;
78 serverResponse.responseText = responseText; 78 serverResponse.responseText = responseText;
79 getCallback(serverResponse); 79 getCallback(serverResponse);
80 } 80 }
81 }; 81 };
82 82
83
84 // To run this test one needs to set INITIAL_DELAY to about 2000 msec 83 // To run this test one needs to set INITIAL_DELAY to about 2000 msec
85 // in notification.js. 84 // in notification.js.
86 class NotificationMockWebRequestTest : public BaseJsTest 85 class NotificationMockWebRequestTest : public BaseJsTest
87 { 86 {
88 protected: 87 protected:
89 bool isNotificationCallbackCalled; 88 bool isNotificationCallbackCalled;
89 DelayedTimer::SharedTasks timerTasks;
90 void SetUp() 90 void SetUp()
91 { 91 {
92 isNotificationCallbackCalled = false; 92 isNotificationCallbackCalled = false;
93 const char* responseJsonText = "{" 93 const char* responseJsonText = "{"
94 "\"notifications\": [{" 94 "\"notifications\": [{"
95 "\"id\": \"some id\"," 95 "\"id\": \"some id\","
96 "\"type\": \"information\"," 96 "\"type\": \"information\","
97 "\"message\": {" 97 "\"message\": {"
98 "\"en-US\": \"message\"" 98 "\"en-US\": \"message\""
99 "}," 99 "},"
100 "\"title\": \"Title\"" 100 "\"title\": \"Title\""
101 "}]" 101 "}]"
102 "}"; 102 "}";
103 103
104 LazyFileSystem* fileSystem;
104 ThrowingPlatformCreationParameters platformParams; 105 ThrowingPlatformCreationParameters platformParams;
105 platformParams.fileSystem.reset(new LazyFileSystem()); 106 platformParams.timer = DelayedTimer::New(timerTasks);
107 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem());
106 platformParams.webRequest.reset(new MockWebRequest(responseJsonText)); 108 platformParams.webRequest.reset(new MockWebRequest(responseJsonText));
107 platform.reset(new Platform(std::move(platformParams))); 109 platform.reset(new Platform(std::move(platformParams)));
108 110
111 CreateFilterEngine(*fileSystem, *platform);
109 auto& filterEngine = platform->GetFilterEngine(); 112 auto& filterEngine = platform->GetFilterEngine();
110 filterEngine.SetShowNotificationCallback( 113 filterEngine.SetShowNotificationCallback(
111 [this](Notification&& notification) { 114 [this](Notification&& notification) {
112 isNotificationCallbackCalled = true; 115 isNotificationCallbackCalled = true;
113 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); 116 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType());
114 EXPECT_EQ("Title", notification.GetTexts().title); 117 EXPECT_EQ("Title", notification.GetTexts().title);
115 EXPECT_EQ("message", notification.GetTexts().message); 118 EXPECT_EQ("message", notification.GetTexts().message);
116 notification.MarkAsShown(); 119 notification.MarkAsShown();
117 }); 120 });
118 } 121 }
119 }; 122 };
120 } 123 }
121 124
122 TEST_F(NotificationTest, NoNotifications) 125 TEST_F(NotificationTest, NoNotifications)
123 { 126 {
124 EXPECT_FALSE(PeekNotification()); 127 EXPECT_FALSE(PeekNotification());
125 } 128 }
126 129
127 TEST_F(NotificationMockWebRequestTest, DISABLED_SingleNotification) 130 TEST_F(NotificationMockWebRequestTest, SingleNotification)
128 { 131 {
129 AdblockPlus::Sleep(5000/*msec*/); // it's a hack 132 auto& filterEngine = platform->GetFilterEngine();
133 auto ii = timerTasks->begin();
134 while(!isNotificationCallbackCalled && ii != timerTasks->end()) {
135 ii->callback();
136 ii = timerTasks->erase(ii);
137 filterEngine.ShowNextNotification();
138 }
130 EXPECT_TRUE(isNotificationCallbackCalled); 139 EXPECT_TRUE(isNotificationCallbackCalled);
131 } 140 }
132 141
133 TEST_F(NotificationTest, AddNotification) 142 TEST_F(NotificationTest, AddNotification)
134 { 143 {
135 AddNotification("{" 144 AddNotification("{"
136 "type: 'critical'," 145 "type: 'critical',"
137 "title: 'testTitle'," 146 "title: 'testTitle',"
138 "message: 'testMessage'," 147 "message: 'testMessage',"
139 "}"); 148 "}");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 TEST_F(NotificationTest, Links) 197 TEST_F(NotificationTest, Links)
189 { 198 {
190 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); 199 AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
191 auto notification = PeekNotification(); 200 auto notification = PeekNotification();
192 ASSERT_TRUE(notification); 201 ASSERT_TRUE(notification);
193 std::vector<std::string> notificationLinks = notification->GetLinks(); 202 std::vector<std::string> notificationLinks = notification->GetLinks();
194 ASSERT_EQ(2u, notificationLinks.size()); 203 ASSERT_EQ(2u, notificationLinks.size());
195 EXPECT_EQ("link1", notificationLinks[0]); 204 EXPECT_EQ("link1", notificationLinks[0]);
196 EXPECT_EQ("link2", notificationLinks[1]); 205 EXPECT_EQ("link2", notificationLinks[1]);
197 } 206 }
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