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

Side by Side Diff: content/browser/shared_worker/shared_worker_instance_unittest.cc

Issue 177043003: Implement SharedWorkerServiceImpl::CreateWorker and SharedWorkerInstance and SharedWorkerHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test for SharedWorkerInstance Created 6 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
OLDNEW
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 "content/browser/frame_host/render_widget_host_view_child_frame.h"
6
7 #include "base/basictypes.h" 5 #include "base/basictypes.h"
8 #include "base/message_loop/message_loop.h" 6 #include "base/memory/scoped_ptr.h"
9 #include "content/browser/renderer_host/render_widget_host_delegate.h" 7 #include "content/browser/shared_worker/shared_worker_instance.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 8 #include "content/browser/worker_host/worker_storage_partition.h"
11 #include "content/common/view_messages.h"
12 #include "content/public/browser/render_widget_host_view.h"
13 #include "content/public/test/mock_render_process_host.h"
14 #include "content/public/test/test_browser_context.h" 9 #include "content/public/test/test_browser_context.h"
15 #include "content/test/test_render_view_host.h"
16 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
17 11
18 namespace content { 12 namespace content {
19 namespace { 13
20 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { 14 class SharedWorkerInstanceTest : public testing::Test {
21 public: 15 protected:
22 MockRenderWidgetHostDelegate() {} 16 SharedWorkerInstanceTest()
23 virtual ~MockRenderWidgetHostDelegate() {} 17 : browser_context_(new TestBrowserContext()),
18 partition_(new WorkerStoragePartition(
19 browser_context_->GetRequestContext(),
20 NULL, NULL, NULL, NULL, NULL, NULL)) {
21 }
22
23 bool Matches(const SharedWorkerInstance& instance,
24 const wchar_t* url,
25 const wchar_t* name) {
kinuko 2014/02/26 14:33:25 nit: Can these just take const std::string& and co
horo 2014/02/26 16:31:22 Changed to use std::string and base::StringPiece
26 return instance.Matches(GURL(url),
27 name,
28 *partition_.get(),
29 browser_context_->GetResourceContext());
30 }
31
32 scoped_ptr<TestBrowserContext> browser_context_;
33 scoped_ptr<WorkerStoragePartition> partition_;
34
35 DISALLOW_COPY_AND_ASSIGN(SharedWorkerInstanceTest);
24 }; 36 };
25 37
26 class RenderWidgetHostViewChildFrameTest : public testing::Test { 38 TEST_F(SharedWorkerInstanceTest, MatchesTest) {
27 public: 39 SharedWorkerInstance instance1(GURL(L"http://example.com/w.js"),
kinuko 2014/02/26 14:33:25 I don't think we need L"" literals for GURL (it ju
horo 2014/02/26 16:31:22 Done.
28 RenderWidgetHostViewChildFrameTest() {} 40 L"",
41 L"",
42 blink::WebContentSecurityPolicyTypeReport,
43 browser_context_->GetResourceContext(),
44 *partition_.get());
45 EXPECT_TRUE(Matches(instance1, L"http://example.com/w.js", L""));
46 EXPECT_FALSE(Matches(instance1, L"http://example.com/w2.js", L""));
47 EXPECT_FALSE(Matches(instance1, L"http://example.net/w.js", L""));
48 EXPECT_FALSE(Matches(instance1, L"http://example.net/w2.js", L""));
49 EXPECT_FALSE(Matches(instance1, L"http://example.com/w.js", L"name"));
50 EXPECT_FALSE(Matches(instance1, L"http://example.com/w2.js", L"name"));
51 EXPECT_FALSE(Matches(instance1, L"http://example.net/w.js", L"name"));
52 EXPECT_FALSE(Matches(instance1, L"http://example.net/w2.js", L"name"));
29 53
30 virtual void SetUp() { 54 SharedWorkerInstance instance2(GURL(L"http://example.com/w.js"),
31 browser_context_.reset(new TestBrowserContext); 55 L"name",
32 MockRenderProcessHost* process_host = 56 L"",
33 new MockRenderProcessHost(browser_context_.get()); 57 blink::WebContentSecurityPolicyTypeReport,
34 widget_host_ = new RenderWidgetHostImpl( 58 browser_context_->GetResourceContext(),
35 &delegate_, process_host, MSG_ROUTING_NONE, false); 59 *partition_.get());
36 view_ = new RenderWidgetHostViewChildFrame(widget_host_); 60 EXPECT_FALSE(Matches(instance2, L"http://example.com/w.js", L""));
37 } 61 EXPECT_FALSE(Matches(instance2, L"http://example.com/w2.js", L""));
38 62 EXPECT_FALSE(Matches(instance2, L"http://example.net/w.js", L""));
39 virtual void TearDown() { 63 EXPECT_FALSE(Matches(instance2, L"http://example.net/w2.js", L""));
40 if (view_) 64 EXPECT_TRUE(Matches(instance2, L"http://example.com/w.js", L"name"));
41 view_->Destroy(); 65 EXPECT_TRUE(Matches(instance2, L"http://example.com/w2.js", L"name"));
42 delete widget_host_; 66 EXPECT_FALSE(Matches(instance2, L"http://example.net/w.js", L"name"));
43 67 EXPECT_FALSE(Matches(instance2, L"http://example.net/w2.js", L"name"));
44 browser_context_.reset(); 68 EXPECT_FALSE(Matches(instance2, L"http://example.com/w.js", L"name2"));
45 69 EXPECT_FALSE(Matches(instance2, L"http://example.com/w2.js", L"name2"));
46 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); 70 EXPECT_FALSE(Matches(instance2, L"http://example.net/w.js", L"name2"));
47 message_loop_.RunUntilIdle(); 71 EXPECT_FALSE(Matches(instance2, L"http://example.net/w2.js", L"name2"));
48 }
49
50 protected:
51 base::MessageLoopForUI message_loop_;
52 scoped_ptr<BrowserContext> browser_context_;
53 MockRenderWidgetHostDelegate delegate_;
54
55 // Tests should set these to NULL if they've already triggered their
56 // destruction.
57 RenderWidgetHostImpl* widget_host_;
58 RenderWidgetHostViewChildFrame* view_;
59
60 private:
61 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewChildFrameTest);
62 };
63
64 } // namespace
65
66 TEST_F(RenderWidgetHostViewChildFrameTest, VisibilityTest) {
67 view_->Show();
68 ASSERT_TRUE(view_->IsShowing());
69
70 view_->Hide();
71 ASSERT_FALSE(view_->IsShowing());
72
73 view_->WasShown();
74 ASSERT_TRUE(view_->IsShowing());
75
76 view_->WasHidden();
77 ASSERT_FALSE(view_->IsShowing());
78 } 72 }
79 73
80 } // namespace content 74 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/shared_worker/shared_worker_instance.cc ('k') | content/browser/shared_worker/shared_worker_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698