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

Side by Side Diff: chrome/browser/extensions/app_notify_channel_setup_unittest.cc

Issue 8194005: Relanding: Add js api for hosted/packaged apps to request notification authorization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/compiler_specific.h"
6 #include "base/memory/weak_ptr.h"
7 #include "base/message_loop.h"
8 #include "chrome/browser/extensions/app_notify_channel_setup.h"
9 #include "content/browser/browser_thread.h"
10 #include "googleurl/src/gurl.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 class TestDelegate : public AppNotifyChannelSetup::Delegate,
16 public base::SupportsWeakPtr<TestDelegate> {
17 public:
18 TestDelegate() was_called_(false) {}
19 virtual ~TestDelegate() {}
20
21 virtual void AppNotifyChannelSetupComplete(
22 int request_id,
23 const std::string& channel_id,
24 const std::string& error) OVERRIDE {
25 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
26 EXPECT_FALSE(was_called_);
27 was_called_ = true;
28 request_id_ = request_id;
29 channel_id_ = channel_id;
30 error_ = error;
31 MessageLoop::current()->Quit();
32 }
33
34 // Called to check that we were called with the expected arguments.
35 void ExpectWasCalled(int expected_request_id,
36 const std::string& expected_channel_id,
37 const std::string& expected_error) {
38 EXPECT_TRUE(was_called_);
39 EXPECT_EQ(expected_request_id, request_id_);
40 EXPECT_EQ(expected_channel_id, channel_id_);
41 EXPECT_EQ(expected_error, error_);
42 }
43
44 private:
45 // Has our callback been called yet?
46 bool was_called_;
47
48 // When our AppNotifyChannelSetupComplete method is called, we copy the
49 // arguments into these member variables.
50 int request_id_;
51 std::string channel_id_;
52 std::string error_;
53
54 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
55 };
56
57 } // namespace
58
59
60 TEST(AppNotifyChannelSetupTest, WasDelegateCalled) {
61 MessageLoop message_loop;
62 BrowserThread thread(BrowserThread::UI, &message_loop);
63
64 TestDelegate delegate;
65 int request_id = 5;
66 std::string client_id = "12345";
67 GURL url("http://www.google.com");
68
69 scoped_refptr<AppNotifyChannelSetup > setup =
70 new AppNotifyChannelSetup(request_id,
71 client_id,
72 url,
73 delegate.AsWeakPtr());
74 setup->Start();
75 MessageLoop::current()->Run();
76 delegate.ExpectWasCalled(
77 request_id, std::string(), std::string("not_implemented"));
78 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_notify_channel_setup.cc ('k') | chrome/browser/extensions/extension_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698