OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/auto_reset.h" | |
6 #include "base/command_line.h" | |
7 #include "base/memory/ptr_util.h" | |
8 #include "chromeos/dbus/dbus_thread_manager.h" | |
9 #include "chromeos/dbus/fake_media_analytics_client.h" | |
10 #include "chromeos/dbus/media_analytics_client.h" | |
11 #include "chromeos/media_perception/media_perception.pb.h" | |
12 #include "extensions/browser/api/media_perception_private/media_perception_priva te_api.h" | |
13 #include "extensions/common/features/feature_session_type.h" | |
14 #include "extensions/common/switches.h" | |
15 #include "extensions/shell/test/shell_apitest.h" | |
16 #include "extensions/test/extension_test_message_listener.h" | |
17 #include "extensions/test/result_catcher.h" | |
18 | |
19 namespace extensions { | |
20 | |
21 class MediaPerceptionPrivateApiTest : public ShellApiTest { | |
22 public: | |
23 MediaPerceptionPrivateApiTest() {} | |
24 ~MediaPerceptionPrivateApiTest() override {} | |
25 | |
26 void SetUpCommandLine(base::CommandLine* command_line) override { | |
27 ShellApiTest::SetUpCommandLine(command_line); | |
28 // Whitelist of the extension ID of the test extension. | |
29 command_line->AppendSwitchASCII( | |
30 extensions::switches::kWhitelistedExtensionID, | |
31 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | |
32 } | |
33 | |
34 void SetUpInProcessBrowserTestFixture() override { | |
35 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = | |
36 chromeos::DBusThreadManager::GetSetterForTesting(); | |
37 auto media_analytics_client = | |
38 base::MakeUnique<chromeos::FakeMediaAnalyticsClient>(); | |
39 media_analytics_client_ = media_analytics_client.get(); | |
40 dbus_setter->SetMediaAnalyticsClient(std::move(media_analytics_client)); | |
41 } | |
42 | |
43 void SetUpOnMainThread() override { | |
44 session_feature_type_ = extensions::ScopedCurrentFeatureSessionType( | |
45 extensions::FeatureSessionType::KIOSK); | |
46 ShellApiTest::SetUpOnMainThread(); | |
47 } | |
48 | |
tbarzic
2017/05/17 21:04:42
private:
Luke Sorenson
2017/05/17 23:07:49
Done.
| |
49 // Ownership is passed on to chromeos::DbusThreadManager. | |
50 chromeos::FakeMediaAnalyticsClient* media_analytics_client_; | |
51 | |
52 std::unique_ptr<base::AutoReset<extensions::FeatureSessionType>> | |
53 session_feature_type_; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(MediaPerceptionPrivateApiTest); | |
56 }; | |
57 | |
58 // Verify that we can set and get mediaPerception system state. | |
59 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, State) { | |
60 ASSERT_TRUE(RunAppTest("media_perception_private/state")) << message_; | |
61 } | |
62 | |
63 // Verify that we can request Diagnostics. | |
64 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, GetDiagnostics) { | |
65 // Allows us to validate that the right data comes through the code path. | |
66 mri::Diagnostics diagnostics; | |
67 diagnostics.add_perception_sample()->mutable_frame_perception()->set_frame_id( | |
68 1); | |
69 media_analytics_client_->SetDiagnostics(diagnostics); | |
70 | |
71 ASSERT_TRUE(RunAppTest("media_perception_private/diagnostics")) << message_; | |
72 } | |
73 | |
74 // Verify that we can listen for MediaPerceptionDetection signals and handle | |
75 // them. | |
76 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, MediaPerception) { | |
77 extensions::ResultCatcher catcher; | |
78 catcher.RestrictToBrowserContext(browser_context()); | |
79 | |
80 ExtensionTestMessageListener handler_registered_listener( | |
81 "mediaPerceptionListenerSet", false); | |
82 ASSERT_TRUE(LoadApp("media_perception_private/media_perception")) << message_; | |
83 ASSERT_TRUE(handler_registered_listener.WaitUntilSatisfied()); | |
84 | |
85 mri::MediaPerception media_perception; | |
86 media_perception.add_frame_perception()->set_frame_id(1); | |
87 ASSERT_TRUE( | |
88 media_analytics_client_->FireMediaPerceptionEvent(media_perception)); | |
89 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
90 } | |
91 | |
92 } // namespace extensions | |
OLD | NEW |