| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "extensions/common/extension.h" | 6 #include "extensions/common/extension.h" |
| 7 #include "extensions/common/features/feature.h" | 7 #include "extensions/common/features/feature.h" |
| 8 #include "extensions/renderer/script_context.h" | 8 #include "extensions/renderer/script_context.h" |
| 9 #include "extensions/renderer/script_context_set.h" | 9 #include "extensions/renderer/script_context_set.h" |
| 10 #include "gin/public/context_holder.h" | 10 #include "gin/public/context_holder.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 context_holder.SetContext(v8::Context::New(isolate)); | 25 context_holder.SetContext(v8::Context::New(isolate)); |
| 26 | 26 |
| 27 // Dirty hack, but we don't actually need the frame, and this is easier than | 27 // Dirty hack, but we don't actually need the frame, and this is easier than |
| 28 // creating a whole webview. | 28 // creating a whole webview. |
| 29 blink::WebFrame* frame = reinterpret_cast<blink::WebFrame*>(1); | 29 blink::WebFrame* frame = reinterpret_cast<blink::WebFrame*>(1); |
| 30 const Extension* extension = NULL; | 30 const Extension* extension = NULL; |
| 31 ScriptContext* context = | 31 ScriptContext* context = |
| 32 new ScriptContext(context_holder.context(), | 32 new ScriptContext(context_holder.context(), |
| 33 frame, | 33 frame, |
| 34 extension, | 34 extension, |
| 35 Feature::BLESSED_EXTENSION_CONTEXT, |
| 36 extension, |
| 35 Feature::BLESSED_EXTENSION_CONTEXT); | 37 Feature::BLESSED_EXTENSION_CONTEXT); |
| 36 | 38 |
| 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 EXPECT_EQ(context, context_set.GetByV8Context(context->v8_context())); | 41 EXPECT_EQ(context, context_set.GetByV8Context(context->v8_context())); |
| 40 | 42 |
| 41 // Adding the same item multiple times should be OK and deduped. | 43 // Adding the same item multiple times should be OK and deduped. |
| 42 context_set.Add(context); | 44 context_set.Add(context); |
| 43 EXPECT_EQ(1u, context_set.GetAll().count(context)); | 45 EXPECT_EQ(1u, context_set.GetAll().count(context)); |
| 44 | 46 |
| 45 // GetAll() returns a copy so removing from one should not remove from others. | 47 // GetAll() returns a copy so removing from one should not remove from others. |
| 46 ScriptContextSet::ContextSet set_copy = context_set.GetAll(); | 48 ScriptContextSet::ContextSet set_copy = context_set.GetAll(); |
| 47 EXPECT_EQ(1u, set_copy.count(context)); | 49 EXPECT_EQ(1u, set_copy.count(context)); |
| 48 | 50 |
| 49 context_set.Remove(context); | 51 context_set.Remove(context); |
| 50 EXPECT_EQ(0, context_set.size()); | 52 EXPECT_EQ(0, context_set.size()); |
| 51 EXPECT_FALSE(context_set.GetByV8Context(context->v8_context())); | 53 EXPECT_FALSE(context_set.GetByV8Context(context->v8_context())); |
| 52 EXPECT_EQ(1u, set_copy.size()); | 54 EXPECT_EQ(1u, set_copy.size()); |
| 53 | 55 |
| 54 // After removal, the context should be marked for destruction. | 56 // After removal, the context should be marked for destruction. |
| 55 EXPECT_FALSE(context->web_frame()); | 57 EXPECT_FALSE(context->web_frame()); |
| 56 | 58 |
| 57 // Run loop to do the actual deletion. | 59 // Run loop to do the actual deletion. |
| 58 loop.RunUntilIdle(); | 60 loop.RunUntilIdle(); |
| 59 } | 61 } |
| 60 | 62 |
| 61 } // namespace extensions | 63 } // namespace extensions |
| OLD | NEW |