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

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

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

Powered by Google App Engine
This is Rietveld 408576698