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

Side by Side Diff: chrome/browser/extensions/api/notifications/extension_notification_handler_unittest.cc

Issue 2875673002: Minimize the delegate dependencies for native extension notifications. (Closed)
Patch Set: review Created 3 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2017 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 <string>
6
7 #include "base/strings/nullable_string16.h"
8 #include "chrome/browser/extensions/api/notifications/extension_notification_han dler.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/test/base/testing_browser_process.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "chrome/test/base/testing_profile_manager.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace extensions {
17 namespace {
18
19 static const char kChromeExtensionOrigin[] =
20 "chrome-extension://gclcddgeeaknflkijpcbplmhbkonmlij/";
21 static const char kChromeExtensionId[] = "gclcddgeeaknflkijpcbplmhbkonmlij";
22 static const char kChromeNotificationId[] =
23 "gclcddgeeaknflkijpcbplmhbkonmlij-id1";
24
25 class TestExtensionNotificationHandler : public ExtensionNotificationHandler {
26 public:
27 // Set expected arguments for this test handler.
28 void SetTestExpectations(const std::string& extension_id,
29 const std::string& event_name,
30 size_t param_count) {
31 extension_id_ = extension_id;
32 event_name_ = event_name;
33 param_count_ = param_count;
34 }
35
36 protected:
37 void SendEvent(Profile* profile,
38 const std::string& extension_id,
39 events::HistogramValue histogram_value,
40 const std::string& event_name,
41 EventRouter::UserGestureState user_gesture,
42 std::unique_ptr<base::ListValue> args) final {
43 EXPECT_EQ(event_name_, event_name);
44 EXPECT_EQ(extension_id_, extension_id);
45 EXPECT_EQ(param_count_, args->GetSize());
46 }
47
48 private:
49 std::string extension_id_;
50 std::string event_name_;
51 size_t param_count_;
52 };
53 } // namespace
54
55 class ExtensionNotificationHandlerTest : public testing::Test {
56 public:
57 ExtensionNotificationHandlerTest()
58 : thread_bundle_(content::TestBrowserThreadBundle::DEFAULT) {}
59
60 private:
61 content::TestBrowserThreadBundle thread_bundle_;
62 };
63
64 TEST_F(ExtensionNotificationHandlerTest, CloseHandler) {
65 EXPECT_TRUE(true);
66 TestingProfile::Builder builder;
67 std::unique_ptr<TestingProfile> profile = builder.Build();
68
69 TestExtensionNotificationHandler handler;
70 handler.SetTestExpectations(kChromeExtensionId, "notifications.onClosed", 2);
71 handler.OnClose(profile.get(), kChromeExtensionOrigin, kChromeNotificationId,
72 false);
73 }
74
75 TEST_F(ExtensionNotificationHandlerTest, ClickHandler) {
76 EXPECT_TRUE(true);
77 TestingProfile::Builder builder;
78 std::unique_ptr<TestingProfile> profile = builder.Build();
79
80 TestExtensionNotificationHandler handler;
81 handler.SetTestExpectations(kChromeExtensionId, "notifications.onClicked", 1);
82 handler.OnClick(profile.get(), kChromeExtensionOrigin, kChromeNotificationId,
83 -1, base::NullableString16() /* reply */);
84 }
85
86 TEST_F(ExtensionNotificationHandlerTest, ClickHandlerButton) {
87 EXPECT_TRUE(true);
88 TestingProfile::Builder builder;
89 std::unique_ptr<TestingProfile> profile = builder.Build();
90
91 TestExtensionNotificationHandler handler;
92 handler.SetTestExpectations(kChromeExtensionId,
93 "notifications.onButtonClicked", 2);
94 handler.OnClick(profile.get(), kChromeExtensionOrigin, kChromeNotificationId,
95 1, base::NullableString16() /* reply */);
96 }
97
98 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698