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

Side by Side Diff: chrome/renderer/extensions/chrome_v8_context_set_unittest.cc

Issue 9403006: Extensions: run "custom bindings" v8-extensions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "chrome/renderer/extensions/chrome_v8_context.h" 6 #include "chrome/renderer/extensions/chrome_v8_context.h"
7 #include "chrome/renderer/extensions/chrome_v8_context_set.h" 7 #include "chrome/renderer/extensions/chrome_v8_context_set.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
10 #include "v8/include/v8.h" 10 #include "v8/include/v8.h"
11 11
12 TEST(ChromeV8ContextSet, Lifecycle) { 12 TEST(ChromeV8ContextSet, Lifecycle) {
13 MessageLoop loop; 13 MessageLoop loop;
14 14
15 ChromeV8ContextSet context_set; 15 ChromeV8ContextSet context_set;
16 16
17 v8::HandleScope handle_scope; 17 v8::HandleScope handle_scope;
18 v8::Handle<v8::Context> v8_context(v8::Context::New()); 18 v8::Handle<v8::Context> v8_context(v8::Context::New());
19 19
20 // Dirty hack, but we don't actually need the frame, and this is easier than 20 // Dirty hack, but we don't actually need the frame, and this is easier than
21 // creating a whole webview. 21 // creating a whole webview.
22 WebKit::WebFrame* frame = reinterpret_cast<WebKit::WebFrame*>(1); 22 WebKit::WebFrame* frame = reinterpret_cast<WebKit::WebFrame*>(1);
23 std::string extension_id = "00000000000000000000000000000000"; 23 std::string extension_id = "00000000000000000000000000000000";
24 ChromeV8Context* context = 24 ChromeV8Context* context =
25 new ChromeV8Context(v8_context, frame, extension_id); 25 new ChromeV8Context(v8_context, frame, extension_id, false);
Aaron Boodman 2012/02/16 00:17:13 Boolean flags stink for readability. Consider addi
not at google - send to devlin 2012/02/16 01:45:53 Done. I'm not sure it's entirely right though. In
Aaron Boodman 2012/02/16 02:01:53 That's a good point. I'm not sure if this is calle
26 26
27 context_set.Add(context); 27 context_set.Add(context);
28 EXPECT_EQ(1u, context_set.GetAll().count(context)); 28 EXPECT_EQ(1u, context_set.GetAll().count(context));
29 EXPECT_EQ(context, context_set.GetByV8Context(context->v8_context())); 29 EXPECT_EQ(context, context_set.GetByV8Context(context->v8_context()));
30 30
31 // Adding the same item multiple times should be OK and deduped. 31 // Adding the same item multiple times should be OK and deduped.
32 context_set.Add(context); 32 context_set.Add(context);
33 EXPECT_EQ(1u, context_set.GetAll().count(context)); 33 EXPECT_EQ(1u, context_set.GetAll().count(context));
34 34
35 // GetAll() returns a copy so removing from one should not remove from others. 35 // GetAll() returns a copy so removing from one should not remove from others.
36 ChromeV8ContextSet::ContextSet set_copy = context_set.GetAll(); 36 ChromeV8ContextSet::ContextSet set_copy = context_set.GetAll();
37 EXPECT_EQ(1u, set_copy.count(context)); 37 EXPECT_EQ(1u, set_copy.count(context));
38 38
39 context_set.Remove(context); 39 context_set.Remove(context);
40 EXPECT_EQ(0, context_set.size()); 40 EXPECT_EQ(0, context_set.size());
41 EXPECT_FALSE(context_set.GetByV8Context(context->v8_context())); 41 EXPECT_FALSE(context_set.GetByV8Context(context->v8_context()));
42 EXPECT_EQ(1u, set_copy.size()); 42 EXPECT_EQ(1u, set_copy.size());
43 43
44 // After removal, the context should be marked for destruction. 44 // After removal, the context should be marked for destruction.
45 EXPECT_FALSE(context->web_frame()); 45 EXPECT_FALSE(context->web_frame());
46 46
47 // Run loop to do the actual deletion. 47 // Run loop to do the actual deletion.
48 loop.RunAllPending(); 48 loop.RunAllPending();
49 } 49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698