OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "extensions/renderer/native_extension_bindings_system.h" | 5 #include "extensions/renderer/native_extension_bindings_system.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "components/crx_file/id_util.h" | 10 #include "components/crx_file/id_util.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 v8::Local<v8::Value> chrome = | 141 v8::Local<v8::Value> chrome = |
142 GetPropertyFromObject(context->Global(), context, "chrome"); | 142 GetPropertyFromObject(context->Global(), context, "chrome"); |
143 ASSERT_FALSE(chrome.IsEmpty()); | 143 ASSERT_FALSE(chrome.IsEmpty()); |
144 ASSERT_TRUE(chrome->IsObject()); | 144 ASSERT_TRUE(chrome->IsObject()); |
145 | 145 |
146 v8::Local<v8::Value> idle = GetPropertyFromObject( | 146 v8::Local<v8::Value> idle = GetPropertyFromObject( |
147 v8::Local<v8::Object>::Cast(chrome), context, "idle"); | 147 v8::Local<v8::Object>::Cast(chrome), context, "idle"); |
148 ASSERT_FALSE(idle.IsEmpty()); | 148 ASSERT_FALSE(idle.IsEmpty()); |
149 ASSERT_TRUE(idle->IsObject()); | 149 ASSERT_TRUE(idle->IsObject()); |
150 | 150 |
151 v8::Local<v8::Value> idle_query_state = GetPropertyFromObject( | 151 v8::Local<v8::Object> idle_object = v8::Local<v8::Object>::Cast(idle); |
152 v8::Local<v8::Object>::Cast(idle), context, "queryState"); | 152 v8::Local<v8::Value> idle_query_state = |
| 153 GetPropertyFromObject(idle_object, context, "queryState"); |
153 ASSERT_FALSE(idle_query_state.IsEmpty()); | 154 ASSERT_FALSE(idle_query_state.IsEmpty()); |
154 | 155 |
| 156 EXPECT_EQ(ReplaceSingleQuotes( |
| 157 "{'ACTIVE':'active','IDLE':'idle','LOCKED':'locked'}"), |
| 158 GetStringPropertyFromObject(idle_object, context, "IdleState")); |
| 159 |
155 { | 160 { |
156 // Try calling the function with an invalid invocation - an error should be | 161 // Try calling the function with an invalid invocation - an error should be |
157 // thrown. | 162 // thrown. |
158 const char kCallIdleQueryStateInvalid[] = | 163 const char kCallIdleQueryStateInvalid[] = |
159 "(function() {\n" | 164 "(function() {\n" |
160 " chrome.idle.queryState('foo', function(state) {\n" | 165 " chrome.idle.queryState('foo', function(state) {\n" |
161 " this.responseState = state;\n" | 166 " this.responseState = state;\n" |
162 " });\n" | 167 " });\n" |
163 "});"; | 168 "});"; |
164 v8::Local<v8::Function> function = | 169 v8::Local<v8::Function> function = |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Next, we need to check two pieces: first, that the custom handler was | 342 // Next, we need to check two pieces: first, that the custom handler was |
338 // called with the proper arguments.... | 343 // called with the proper arguments.... |
339 EXPECT_EQ("30", GetStringPropertyFromObject(global, context, "timeArg")); | 344 EXPECT_EQ("30", GetStringPropertyFromObject(global, context, "timeArg")); |
340 | 345 |
341 // ...and second, that the callback was called with the proper result. | 346 // ...and second, that the callback was called with the proper result. |
342 EXPECT_EQ("\"active\"", | 347 EXPECT_EQ("\"active\"", |
343 GetStringPropertyFromObject(global, context, "responseState")); | 348 GetStringPropertyFromObject(global, context, "responseState")); |
344 } | 349 } |
345 | 350 |
346 } // namespace extensions | 351 } // namespace extensions |
OLD | NEW |