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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/app_notify_channel_setup_unittest.cc
diff --git a/chrome/browser/extensions/app_notify_channel_setup_unittest.cc b/chrome/browser/extensions/app_notify_channel_setup_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9727ec94de85e27463e845e464ede077eda604d6
--- /dev/null
+++ b/chrome/browser/extensions/app_notify_channel_setup_unittest.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop.h"
+#include "chrome/browser/extensions/app_notify_channel_setup.h"
+#include "content/browser/browser_thread.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class TestDelegate : public AppNotifyChannelSetup::Delegate,
+ public base::SupportsWeakPtr<TestDelegate> {
+ public:
+ TestDelegate() was_called_(false) {}
+ virtual ~TestDelegate() {}
+
+ virtual void AppNotifyChannelSetupComplete(
+ int request_id,
+ const std::string& channel_id,
+ const std::string& error) OVERRIDE {
+ EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ EXPECT_FALSE(was_called_);
+ was_called_ = true;
+ request_id_ = request_id;
+ channel_id_ = channel_id;
+ error_ = error;
+ MessageLoop::current()->Quit();
+ }
+
+ // Called to check that we were called with the expected arguments.
+ void ExpectWasCalled(int expected_request_id,
+ const std::string& expected_channel_id,
+ const std::string& expected_error) {
+ EXPECT_TRUE(was_called_);
+ EXPECT_EQ(expected_request_id, request_id_);
+ EXPECT_EQ(expected_channel_id, channel_id_);
+ EXPECT_EQ(expected_error, error_);
+ }
+
+ private:
+ // Has our callback been called yet?
+ bool was_called_;
+
+ // When our AppNotifyChannelSetupComplete method is called, we copy the
+ // arguments into these member variables.
+ int request_id_;
+ std::string channel_id_;
+ std::string error_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestDelegate);
+};
+
+} // namespace
+
+
+TEST(AppNotifyChannelSetupTest, WasDelegateCalled) {
+ MessageLoop message_loop;
+ BrowserThread thread(BrowserThread::UI, &message_loop);
+
+ TestDelegate delegate;
+ int request_id = 5;
+ std::string client_id = "12345";
+ GURL url("http://www.google.com");
+
+ scoped_refptr<AppNotifyChannelSetup > setup =
+ new AppNotifyChannelSetup(request_id,
+ client_id,
+ url,
+ delegate.AsWeakPtr());
+ setup->Start();
+ MessageLoop::current()->Run();
+ delegate.ExpectWasCalled(
+ request_id, std::string(), std::string("not_implemented"));
+}
« 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