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

Delta Between Two Patch Sets: test/Notification.cpp

Issue 29371607: Issue #3593 - Make isolate a fully internal member of the engine
Left Patch Set: Created Jan. 12, 2017, 2:46 p.m.
Right Patch Set: improve unit tests to go with isolate change Created Jan. 16, 2017, 3:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « test/JsEngine.cpp ('k') | test/Prefs.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 16 matching lines...) Expand all
27 { 27 {
28 typedef std::shared_ptr<FilterEngine> FilterEnginePtr; 28 typedef std::shared_ptr<FilterEngine> FilterEnginePtr;
29 29
30 class NotificationTest : public BaseJsTest 30 class NotificationTest : public BaseJsTest
31 { 31 {
32 protected: 32 protected:
33 FilterEnginePtr filterEngine; 33 FilterEnginePtr filterEngine;
34 void SetUp() 34 void SetUp()
35 { 35 {
36 BaseJsTest::SetUp(); 36 BaseJsTest::SetUp();
37 jsEngine->SetFileSystem(FileSystemPtr(new LazyFileSystem())); 37 jsEngine->SetFileSystem(std::make_shared<LazyFileSystem>());
38 jsEngine->SetWebRequest(WebRequestPtr(new LazyWebRequest())); 38 jsEngine->SetWebRequest(std::make_shared<LazyWebRequest>());
39 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); 39 jsEngine->SetLogSystem(std::make_shared<DefaultLogSystem>());
40 filterEngine.reset(new FilterEngine(jsEngine)); 40 filterEngine = std::make_shared<FilterEngine>(jsEngine);
41 }
42
43 void TearDown()
44 {
45 filterEngine.reset();
46 BaseJsTest::TearDown();
41 } 47 }
42 48
43 void AddNotification(const std::string& notification) 49 void AddNotification(const std::string& notification)
44 { 50 {
45 jsEngine->Evaluate("(function()" 51 jsEngine->Evaluate("(function()"
46 "{" 52 "{"
47 "require('notification').Notification.addNotification(" + notification + ");" 53 "require('notification').Notification.addNotification(" + notification + ");"
48 "})();"); 54 "})();");
49 } 55 }
50 56
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #ifdef NotificationMockWebRequestTest_ENABLED 98 #ifdef NotificationMockWebRequestTest_ENABLED
93 class NotificationMockWebRequestTest : public BaseJsTest 99 class NotificationMockWebRequestTest : public BaseJsTest
94 { 100 {
95 protected: 101 protected:
96 FilterEnginePtr filterEngine; 102 FilterEnginePtr filterEngine;
97 bool isNotificationCallbackCalled; 103 bool isNotificationCallbackCalled;
98 void SetUp() 104 void SetUp()
99 { 105 {
100 BaseJsTest::SetUp(); 106 BaseJsTest::SetUp();
101 isNotificationCallbackCalled = false; 107 isNotificationCallbackCalled = false;
102 jsEngine->SetFileSystem( 108 jsEngine->SetFileSystem(std::shared_ptr<LazyFileSystem>());
103 std::shared_ptr<LazyFileSystem>(new LazyFileSystem()));
104 const char* responseJsonText = "{" 109 const char* responseJsonText = "{"
105 "\"notifications\": [{" 110 "\"notifications\": [{"
106 "\"id\": \"some id\"," 111 "\"id\": \"some id\","
107 "\"type\": \"information\"," 112 "\"type\": \"information\","
108 "\"message\": {" 113 "\"message\": {"
109 "\"en-US\": \"message\"" 114 "\"en-US\": \"message\""
110 "}," 115 "},"
111 "\"title\": \"Title\"" 116 "\"title\": \"Title\""
112 "}]" 117 "}]"
113 "}"; 118 "}";
114 jsEngine->SetWebRequest(std::shared_ptr<MockWebRequest>( 119 jsEngine->SetWebRequest(std::make_shared<MockWebRequest>(responseJsonText) );
115 new MockWebRequest(responseJsonText))); 120 jsEngine->SetLogSystem(std::make_shared<DefaultLogSystem>());
116 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); 121 filterEngine = std::make_shared<FilterEngine>(jsEngine);
117 filterEngine.reset(new FilterEngine(jsEngine));
118 filterEngine->SetShowNotificationCallback( 122 filterEngine->SetShowNotificationCallback(
119 std::bind(&NotificationMockWebRequestTest::OnNotification, 123 std::bind(&NotificationMockWebRequestTest::OnNotification,
120 this, std::placeholders::_1)); 124 this, std::placeholders::_1));
125 }
126
127 void TearDown()
128 {
129 filterEngine.reset();
130 BaseJsTest::TearDown();
121 } 131 }
122 132
123 void OnNotification(const NotificationPtr& notification) 133 void OnNotification(const NotificationPtr& notification)
124 { 134 {
125 isNotificationCallbackCalled = true; 135 isNotificationCallbackCalled = true;
126 ASSERT_TRUE(notification); 136 ASSERT_TRUE(notification);
127 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->G etType()); 137 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->G etType());
128 EXPECT_EQ("Title", notification->GetTexts().title); 138 EXPECT_EQ("Title", notification->GetTexts().title);
129 EXPECT_EQ("message", notification->GetTexts().message); 139 EXPECT_EQ("message", notification->GetTexts().message);
130 notification->MarkAsShown(); 140 notification->MarkAsShown();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 TEST_F(NotificationTest, Links) 214 TEST_F(NotificationTest, Links)
205 { 215 {
206 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); 216 AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
207 NotificationPtr notification = PeekNotification(); 217 NotificationPtr notification = PeekNotification();
208 ASSERT_TRUE(notification); 218 ASSERT_TRUE(notification);
209 std::vector<std::string> notificationLinks = notification->GetLinks(); 219 std::vector<std::string> notificationLinks = notification->GetLinks();
210 ASSERT_EQ(2, notificationLinks.size()); 220 ASSERT_EQ(2, notificationLinks.size());
211 EXPECT_EQ("link1", notificationLinks[0]); 221 EXPECT_EQ("link1", notificationLinks[0]);
212 EXPECT_EQ("link2", notificationLinks[1]); 222 EXPECT_EQ("link2", notificationLinks[1]);
213 } 223 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld