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 |
| 49 // Ownership is passed on to chromeos::DbusThreadManager. |
| 50 chromeos::FakeMediaAnalyticsClient* media_analytics_client_; |
| 51 |
| 52 private: |
| 53 std::unique_ptr<base::AutoReset<extensions::FeatureSessionType>> |
| 54 session_feature_type_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(MediaPerceptionPrivateApiTest); |
| 57 }; |
| 58 |
| 59 // Verify that we can set and get mediaPerception system state. |
| 60 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, State) { |
| 61 ASSERT_TRUE(RunAppTest("media_perception_private/state")) << message_; |
| 62 } |
| 63 |
| 64 // Verify that we can request Diagnostics. |
| 65 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, GetDiagnostics) { |
| 66 // Allows us to validate that the right data comes through the code path. |
| 67 mri::Diagnostics diagnostics; |
| 68 diagnostics.add_perception_sample()->mutable_frame_perception()->set_frame_id( |
| 69 1); |
| 70 media_analytics_client_->SetDiagnostics(diagnostics); |
| 71 |
| 72 ASSERT_TRUE(RunAppTest("media_perception_private/diagnostics")) << message_; |
| 73 } |
| 74 |
| 75 // Verify that we can listen for MediaPerceptionDetection signals and handle |
| 76 // them. |
| 77 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, MediaPerception) { |
| 78 extensions::ResultCatcher catcher; |
| 79 catcher.RestrictToBrowserContext(browser_context()); |
| 80 |
| 81 ExtensionTestMessageListener handler_registered_listener( |
| 82 "mediaPerceptionListenerSet", false); |
| 83 ASSERT_TRUE(LoadApp("media_perception_private/media_perception")) << message_; |
| 84 ASSERT_TRUE(handler_registered_listener.WaitUntilSatisfied()); |
| 85 |
| 86 mri::MediaPerception media_perception; |
| 87 media_perception.add_frame_perception()->set_frame_id(1); |
| 88 ASSERT_TRUE( |
| 89 media_analytics_client_->FireMediaPerceptionEvent(media_perception)); |
| 90 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 91 } |
| 92 |
| 93 } // namespace extensions |
OLD | NEW |