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

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

Issue 10821133: Move c/r/extensions/* into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for cq Created 8 years, 4 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
OLDNEW
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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "chrome/common/extensions/extension.h" 6 #include "chrome/common/extensions/extension.h"
7 #include "chrome/common/extensions/features/feature.h" 7 #include "chrome/common/extensions/features/feature.h"
8 #include "chrome/renderer/extensions/chrome_v8_context.h" 8 #include "chrome/renderer/extensions/chrome_v8_context.h"
9 #include "chrome/renderer/extensions/chrome_v8_context_set.h" 9 #include "chrome/renderer/extensions/chrome_v8_context_set.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
12 #include "v8/include/v8.h" 12 #include "v8/include/v8.h"
13 13
14 namespace extensions {
15
14 TEST(ChromeV8ContextSet, Lifecycle) { 16 TEST(ChromeV8ContextSet, Lifecycle) {
15 MessageLoop loop; 17 MessageLoop loop;
16 18
17 ChromeV8ContextSet context_set; 19 ChromeV8ContextSet context_set;
18 20
19 v8::HandleScope handle_scope; 21 v8::HandleScope handle_scope;
20 v8::Handle<v8::Context> v8_context(v8::Context::New()); 22 v8::Handle<v8::Context> v8_context(v8::Context::New());
21 23
22 // Dirty hack, but we don't actually need the frame, and this is easier than 24 // Dirty hack, but we don't actually need the frame, and this is easier than
23 // creating a whole webview. 25 // creating a whole webview.
24 WebKit::WebFrame* frame = reinterpret_cast<WebKit::WebFrame*>(1); 26 WebKit::WebFrame* frame = reinterpret_cast<WebKit::WebFrame*>(1);
25 const extensions::Extension* extension = NULL; 27 const Extension* extension = NULL;
26 ChromeV8Context* context = new ChromeV8Context( 28 ChromeV8Context* context = new ChromeV8Context(
27 v8_context, 29 v8_context,
28 frame, 30 frame,
29 extension, 31 extension,
30 extensions::Feature::BLESSED_EXTENSION_CONTEXT); 32 Feature::BLESSED_EXTENSION_CONTEXT);
31 33
32 context_set.Add(context); 34 context_set.Add(context);
33 EXPECT_EQ(1u, context_set.GetAll().count(context)); 35 EXPECT_EQ(1u, context_set.GetAll().count(context));
34 EXPECT_EQ(context, context_set.GetByV8Context(context->v8_context())); 36 EXPECT_EQ(context, context_set.GetByV8Context(context->v8_context()));
35 37
36 // Adding the same item multiple times should be OK and deduped. 38 // Adding the same item multiple times should be OK and deduped.
37 context_set.Add(context); 39 context_set.Add(context);
38 EXPECT_EQ(1u, context_set.GetAll().count(context)); 40 EXPECT_EQ(1u, context_set.GetAll().count(context));
39 41
40 // GetAll() returns a copy so removing from one should not remove from others. 42 // GetAll() returns a copy so removing from one should not remove from others.
41 ChromeV8ContextSet::ContextSet set_copy = context_set.GetAll(); 43 ChromeV8ContextSet::ContextSet set_copy = context_set.GetAll();
42 EXPECT_EQ(1u, set_copy.count(context)); 44 EXPECT_EQ(1u, set_copy.count(context));
43 45
44 context_set.Remove(context); 46 context_set.Remove(context);
45 EXPECT_EQ(0, context_set.size()); 47 EXPECT_EQ(0, context_set.size());
46 EXPECT_FALSE(context_set.GetByV8Context(context->v8_context())); 48 EXPECT_FALSE(context_set.GetByV8Context(context->v8_context()));
47 EXPECT_EQ(1u, set_copy.size()); 49 EXPECT_EQ(1u, set_copy.size());
48 50
49 // After removal, the context should be marked for destruction. 51 // After removal, the context should be marked for destruction.
50 EXPECT_FALSE(context->web_frame()); 52 EXPECT_FALSE(context->web_frame());
51 53
52 // Run loop to do the actual deletion. 54 // Run loop to do the actual deletion.
53 loop.RunAllPending(); 55 loop.RunAllPending();
54 } 56 }
57
58 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/chrome_v8_context_set.cc ('k') | chrome/renderer/extensions/chrome_v8_extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698