OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/api/identity/identity_api.h" | 10 #include "chrome/browser/extensions/api/identity/identity_api.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 namespace extensions { | 41 namespace extensions { |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 namespace errors = identity_constants; | 45 namespace errors = identity_constants; |
46 namespace utils = extension_function_test_utils; | 46 namespace utils = extension_function_test_utils; |
47 | 47 |
48 static const char kAccessToken[] = "auth_token"; | 48 static const char kAccessToken[] = "auth_token"; |
49 static const char kExtensionId[] = "ext_id"; | 49 static const char kExtensionId[] = "ext_id"; |
50 | 50 |
51 // This helps us be able to wait until an AsyncExtensionFunction calls | 51 // This helps us be able to wait until an UIThreadExtensionFunction calls |
52 // SendResponse. | 52 // SendResponse. |
53 class SendResponseDelegate | 53 class SendResponseDelegate |
54 : public UIThreadExtensionFunction::DelegateForTests { | 54 : public UIThreadExtensionFunction::DelegateForTests { |
55 public: | 55 public: |
56 SendResponseDelegate() : should_post_quit_(false) {} | 56 SendResponseDelegate() : should_post_quit_(false) {} |
57 | 57 |
58 virtual ~SendResponseDelegate() {} | 58 virtual ~SendResponseDelegate() {} |
59 | 59 |
60 void set_should_post_quit(bool should_quit) { | 60 void set_should_post_quit(bool should_quit) { |
61 should_post_quit_ = should_quit; | 61 should_post_quit_ = should_quit; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 function->SetArgs(parsed_args.get()); | 102 function->SetArgs(parsed_args.get()); |
103 | 103 |
104 if (!function->GetExtension()) { | 104 if (!function->GetExtension()) { |
105 scoped_refptr<Extension> empty_extension( | 105 scoped_refptr<Extension> empty_extension( |
106 utils::CreateEmptyExtension()); | 106 utils::CreateEmptyExtension()); |
107 function->set_extension(empty_extension.get()); | 107 function->set_extension(empty_extension.get()); |
108 } | 108 } |
109 | 109 |
110 function->set_browser_context(browser()->profile()); | 110 function->set_browser_context(browser()->profile()); |
111 function->set_has_callback(true); | 111 function->set_has_callback(true); |
112 function->Run(); | 112 function->Run()->Execute(); |
113 } | 113 } |
114 | 114 |
115 std::string WaitForError(UIThreadExtensionFunction* function) { | 115 std::string WaitForError(UIThreadExtensionFunction* function) { |
116 RunMessageLoopUntilResponse(); | 116 RunMessageLoopUntilResponse(); |
117 EXPECT_FALSE(function->GetResultList()) << "Did not expect a result"; | 117 EXPECT_FALSE(function->GetResultList()) << "Did not expect a result"; |
118 return function->GetError(); | 118 return function->GetError(); |
119 } | 119 } |
120 | 120 |
121 base::Value* WaitForSingleResult(UIThreadExtensionFunction* function) { | 121 base::Value* WaitForSingleResult(UIThreadExtensionFunction* function) { |
122 RunMessageLoopUntilResponse(); | 122 RunMessageLoopUntilResponse(); |
123 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " | 123 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " |
124 << function->GetError(); | 124 << function->GetError(); |
125 const base::Value* single_result = NULL; | 125 const base::Value* single_result = NULL; |
126 if (function->GetResultList() != NULL && | 126 if (function->GetResultList() != NULL && |
127 function->GetResultList()->Get(0, &single_result)) { | 127 function->GetResultList()->Get(0, &single_result)) { |
128 return single_result->DeepCopy(); | 128 return single_result->DeepCopy(); |
129 } | 129 } |
130 return NULL; | 130 return NULL; |
131 } | 131 } |
132 | 132 |
133 private: | 133 private: |
134 void RunMessageLoopUntilResponse() { | 134 void RunMessageLoopUntilResponse() { |
135 // If the RunImpl of |function| didn't already call SendResponse, run the | 135 // If the RunAsync of |function| didn't already call SendResponse, run the |
136 // message loop until they do. | 136 // message loop until they do. |
137 if (!response_delegate_->HasResponse()) { | 137 if (!response_delegate_->HasResponse()) { |
138 response_delegate_->set_should_post_quit(true); | 138 response_delegate_->set_should_post_quit(true); |
139 content::RunMessageLoop(); | 139 content::RunMessageLoop(); |
140 } | 140 } |
141 EXPECT_TRUE(response_delegate_->HasResponse()); | 141 EXPECT_TRUE(response_delegate_->HasResponse()); |
142 } | 142 } |
143 | 143 |
144 scoped_ptr<SendResponseDelegate> response_delegate_; | 144 scoped_ptr<SendResponseDelegate> response_delegate_; |
145 }; | 145 }; |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1328 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1329 url); | 1329 url); |
1330 } | 1330 } |
1331 | 1331 |
1332 } // namespace extensions | 1332 } // namespace extensions |
1333 | 1333 |
1334 // Tests the chrome.identity API implemented by custom JS bindings . | 1334 // Tests the chrome.identity API implemented by custom JS bindings . |
1335 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1335 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
1336 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1336 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
1337 } | 1337 } |
OLD | NEW |