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

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

Issue 8727024: Save the oauth client id used in App Notification setup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed nits Created 9 years 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
« no previous file with comments | « no previous file | chrome/browser/extensions/app_notify_channel_setup.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h"
6 #include "chrome/browser/extensions/app_notify_channel_setup.h"
7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/browser_thread.h"
15
16 using content::BrowserThread;
17
18 class AppNotificationTest : public ExtensionBrowserTest {
19 public:
20 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
21 ExtensionBrowserTest::SetUpCommandLine(command_line);
22 command_line->AppendSwitch(
23 switches::kEnableExperimentalExtensionApis);
24 }
25 };
26
27 namespace {
28
29 // Our test app will call the getNotificationChannel API using this client id.
30 static const char* kExpectedClientId = "dummy_client_id";
31
32 class Interceptor : public AppNotifyChannelSetup::InterceptorForTests {
33 public:
34 Interceptor() : was_called_(false) {}
35 virtual ~Interceptor() {}
36
37 virtual void DoIntercept(const AppNotifyChannelSetup* setup,
38 std::string* result_channel_id,
39 std::string* result_error) OVERRIDE {
40 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 EXPECT_TRUE(setup->client_id() == std::string(kExpectedClientId));
42 *result_channel_id = std::string("1234");
43 *result_error = std::string();
44 was_called_ = true;
45 MessageLoop::current()->Quit();
46 }
47
48 bool was_called() const { return was_called_; }
49
50 private:
51 bool was_called_;
52 };
53
54
55 } // namespace
56
57 // A test that makes sure we properly save the client id we were passed when
58 // the app called the getNotificationChannel API.
59 IN_PROC_BROWSER_TEST_F(AppNotificationTest, SaveClientId) {
60 Interceptor interceptor;
61 AppNotifyChannelSetup::SetInterceptorForTests(&interceptor);
62
63 const Extension* app =
64 LoadExtension(test_data_dir_.AppendASCII("app_notifications"));
65 ASSERT_TRUE(app != NULL);
66
67 Browser::OpenApplication(browser()->profile(),
68 app,
69 extension_misc::LAUNCH_TAB,
70 GURL(),
71 NEW_FOREGROUND_TAB);
72 if (!interceptor.was_called())
73 ui_test_utils::RunMessageLoop();
74 EXPECT_TRUE(interceptor.was_called());
75
76 ExtensionService* service = browser()->profile()->GetExtensionService();
77 ExtensionPrefs* prefs = service->extension_prefs();
78 std::string saved_id = prefs->GetAppNotificationClientId(app->id());
79 EXPECT_TRUE(std::string(kExpectedClientId) == saved_id);
80 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/app_notify_channel_setup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698