OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
7 #include "remoting/client/plugin/chromoting_plugin.h" | 7 #include "remoting/client/plugin/chromoting_plugin.h" |
8 #include "remoting/client/pepper/fake_browser.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
10 | 9 |
11 // Routine to create the PepperPlugin subclass that implements all of the | |
12 // plugin-specific functionality. | |
13 pepper::PepperPlugin* CreatePlugin(NPNetscapeFuncs* browser_funcs, | |
14 NPP instance); | |
15 | |
16 namespace remoting { | 10 namespace remoting { |
17 | 11 |
| 12 // TODO(ajwong): Once ChromotingPlugin stablizes a little more, come up with |
| 13 // sane unittests. |
18 class ChromotingPluginTest : public testing::Test { | 14 class ChromotingPluginTest : public testing::Test { |
19 protected: | 15 protected: |
20 | |
21 virtual void SetUp() { | 16 virtual void SetUp() { |
22 // Set up the fake browser callback routines. | |
23 fake_browser_ = Singleton<FakeBrowser>::get(); | |
24 NPNetscapeFuncs* browser_funcs_ = fake_browser_->GetBrowserFuncs(); | |
25 instance_.reset(new NPP_t()); | |
26 | |
27 // Create the ChromotingPlugin for testing. | |
28 pepper::PepperPlugin* pepper_plugin = | |
29 CreatePlugin(browser_funcs_, instance_.get()); | |
30 plugin_.reset( | |
31 static_cast<ChromotingPlugin*>(pepper_plugin)); | |
32 } | 17 } |
33 | |
34 virtual void TearDown() { | |
35 } | |
36 | |
37 FakeBrowser* fake_browser_; | |
38 scoped_ptr<NPP_t> instance_; | |
39 scoped_ptr<ChromotingPlugin> plugin_; | |
40 }; | 18 }; |
41 | 19 |
42 TEST_F(ChromotingPluginTest, TestCaseSetup) { | |
43 ASSERT_TRUE(plugin_->browser() != NULL); | |
44 ASSERT_TRUE(plugin_->extensions() != NULL); | |
45 ASSERT_TRUE(plugin_->instance() != NULL); | |
46 | |
47 // Device is not set until New() is called. | |
48 ASSERT_TRUE(plugin_->device() == NULL); | |
49 } | |
50 | |
51 #if 0 | |
52 TODO(ajwong): reenable once we have the threading sorted out. | |
53 TEST_F(ChromotingPluginTest, TestNew) { | |
54 NPMIMEType mimetype = | |
55 const_cast<NPMIMEType>("pepper-application/x-chromoting-plugin"); | |
56 int16 argc; | |
57 char* argn[4]; | |
58 char* argv[4]; | |
59 | |
60 // Test 0 arguments. | |
61 argc = 0; | |
62 ASSERT_EQ(NPERR_GENERIC_ERROR, plugin_->New(mimetype, argc, argn, argv)); | |
63 | |
64 // Test 1 argument (missing "src"). | |
65 argc = 1; | |
66 argn[0] = const_cast<char*>("noturl"); | |
67 argv[0] = const_cast<char*>("random.value"); | |
68 ASSERT_EQ(NPERR_GENERIC_ERROR, plugin_->New(mimetype, argc, argn, argv)); | |
69 | |
70 // Test "src" argument. | |
71 argc = 1; | |
72 argn[0] = const_cast<char*>("src"); | |
73 argv[0] = const_cast<char*>("chromotocol://name?user=u&auth=a&jid=j"); | |
74 ASSERT_EQ(NPERR_NO_ERROR, plugin_->New(mimetype, argc, argn, argv)); | |
75 | |
76 ASSERT_EQ(NPERR_NO_ERROR, plugin_->Destroy(NULL)); | |
77 } | |
78 | |
79 TEST_F(ChromotingPluginTest, TestSetWindow) { | |
80 NPWindow* window = fake_browser_->GetWindow(); | |
81 NPError result; | |
82 | |
83 result = plugin_->SetWindow(window); | |
84 ASSERT_EQ(NPERR_NO_ERROR, result); | |
85 } | |
86 #endif | |
87 | |
88 TEST_F(ChromotingPluginTest, ParseUrl) { | 20 TEST_F(ChromotingPluginTest, ParseUrl) { |
89 const char url[] = "chromotocol://hostid?user=auser&auth=someauth&jid=ajid"; | 21 const char url[] = "chromotocol://hostid?user=auser&auth=someauth&jid=ajid"; |
90 std::string user_id; | 22 std::string user_id; |
91 std::string auth_token; | 23 std::string auth_token; |
92 std::string host_jid; | 24 std::string host_jid; |
93 ASSERT_TRUE( | 25 ASSERT_TRUE( |
94 ChromotingPlugin::ParseUrl(url, &user_id, &auth_token, &host_jid)); | 26 ChromotingPlugin::ParseUrl(url, &user_id, &auth_token, &host_jid)); |
95 | 27 |
96 EXPECT_EQ("auser", user_id); | 28 EXPECT_EQ("auser", user_id); |
97 EXPECT_EQ("someauth", auth_token); | 29 EXPECT_EQ("someauth", auth_token); |
98 EXPECT_EQ("ajid", host_jid); | 30 EXPECT_EQ("ajid", host_jid); |
99 } | 31 } |
100 | 32 |
101 } // namespace remoting | 33 } // namespace remoting |
OLD | NEW |