Chromium Code Reviews| Index: extensions/browser/api/media_perception_private/media_perception_private_apitest.cc |
| diff --git a/extensions/browser/api/media_perception_private/media_perception_private_apitest.cc b/extensions/browser/api/media_perception_private/media_perception_private_apitest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c512685db1d34407246fcd80873c8f5410967b0a |
| --- /dev/null |
| +++ b/extensions/browser/api/media_perception_private/media_perception_private_apitest.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "chrome/browser/extensions/extension_apitest.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "chromeos/dbus/fake_media_analytics_client.h" |
| +#include "chromeos/dbus/media_analytics_client.h" |
| +#include "extensions/browser/api/media_perception_private/media_perception_private_api.h" |
| +#include "extensions/common/switches.h" |
| +#include "extensions/test/extension_test_message_listener.h" |
| + |
| +namespace extensions { |
| + |
| +class MediaPerceptionPrivateApiTest : public ExtensionApiTest { |
| + public: |
| + MediaPerceptionPrivateApiTest() {} |
| + |
| + void SetUpCommandLine(base::CommandLine* command_line) override { |
| + ExtensionApiTest::SetUpCommandLine(command_line); |
| + // Whitelist of the extension ID of the test extension. |
| + command_line->AppendSwitchASCII( |
| + extensions::switches::kWhitelistedExtensionID, |
| + "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
| + } |
| + |
| + void InitializeDbusClient() { |
|
tbarzic
2017/05/11 00:38:27
This is not really initializing D bus client, mayb
Luke Sorenson
2017/05/11 23:58:00
Done.
|
| + dbus_client_ = reinterpret_cast<chromeos::FakeMediaAnalyticsClient*>( |
|
tbarzic
2017/05/11 00:38:27
Can you check if you can use DBusThreadManager::G
Luke Sorenson
2017/05/11 23:57:59
Done.
|
| + chromeos::DBusThreadManager::Get()->GetMediaAnalyticsClient()); |
| + } |
| + |
| + ~MediaPerceptionPrivateApiTest() override {} |
|
tbarzic
2017/05/11 00:38:27
move this after ctor;
use = default where possible
Luke Sorenson
2017/05/11 23:57:59
Done.
|
| + |
| + chromeos::FakeMediaAnalyticsClient* dbus_client_; |
|
tbarzic
2017/05/11 00:38:27
DISALLOW_COPY_AND_ASSIGN
Luke Sorenson
2017/05/11 23:57:59
Done.
|
| +}; |
| + |
| +// Verify that we can set and get mediaPerception system state. |
| +IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, State) { |
| + ASSERT_TRUE(RunPlatformAppTest("media_perception_private/state")) << message_; |
| +} |
| + |
| +// Verify that we can request Diagnostics. |
| +IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, GetDiagnostics) { |
| + InitializeDbusClient(); |
| + // Allows us to validate that the right data comes through the code path. |
| + dbus_client_->SetFrameId(1); |
| + |
| + ASSERT_TRUE(RunPlatformAppTest("media_perception_private/diagnostics")) |
| + << message_; |
| +} |
| + |
| +// Verify that we can listen for MediaPerceptionDetection signals and handle |
| +// them. |
| +IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, MediaPerception) { |
| + ExtensionTestMessageListener handler_registered_listener( |
| + "mediaPerceptionListenerSet", false); |
| + ASSERT_TRUE(LoadExtension( |
| + test_data_dir_.AppendASCII("media_perception_private/media_perception"))) |
| + << message_; |
| + ASSERT_TRUE(handler_registered_listener.WaitUntilSatisfied()); |
| + |
| + InitializeDbusClient(); |
| + // Allows us to validate that the right data comes through the code path. |
| + dbus_client_->SetFrameId(1); |
|
tbarzic
2017/05/11 00:38:27
do you need this for this test?
Luke Sorenson
2017/05/11 23:57:59
Done.
|
| + dbus_client_->FireMediaPerceptionEvent(); |
| +} |
| + |
| +} // namespace extensions |