OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 <string> |
| 6 |
| 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 10 #include "chromeos/dbus/fake_debug_daemon_client.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "extensions/common/extension_builder.h" |
| 13 #include "net/dns/mock_host_resolver.h" |
| 14 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 15 #include "net/test/embedded_test_server/http_request.h" |
| 16 #include "net/test/embedded_test_server/http_response.h" |
| 17 |
| 18 using net::test_server::BasicHttpResponse; |
| 19 using net::test_server::HttpResponse; |
| 20 using net::test_server::HttpRequest; |
| 21 |
| 22 namespace { |
| 23 |
| 24 const char kFileData[] = "log file content"; |
| 25 |
| 26 class TestDebugDaemonClient : public chromeos::FakeDebugDaemonClient { |
| 27 public: |
| 28 TestDebugDaemonClient() { |
| 29 } |
| 30 |
| 31 virtual ~TestDebugDaemonClient() { |
| 32 } |
| 33 |
| 34 virtual void GetDebugLogs(base::File file, |
| 35 const GetDebugLogsCallback& callback) OVERRIDE { |
| 36 base::File* file_param = new base::File(file.Pass()); |
| 37 content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 38 FROM_HERE, |
| 39 base::Bind(&GenerateTestLogDumpFile, base::Owned(file_param)), |
| 40 base::Bind(callback, true)); |
| 41 } |
| 42 |
| 43 static void GenerateTestLogDumpFile(base::File* file) { |
| 44 const std::string write_data(kFileData); |
| 45 const int data_size = static_cast<int>(write_data.size()); |
| 46 EXPECT_EQ(data_size, file->Write(0, write_data.c_str(), data_size)); |
| 47 EXPECT_TRUE(file->SetLength(data_size)); |
| 48 file->Close(); |
| 49 } |
| 50 }; |
| 51 |
| 52 } // namespace |
| 53 |
| 54 namespace extensions { |
| 55 |
| 56 class LogPrivateApiTest : public ExtensionApiTest { |
| 57 public: |
| 58 LogPrivateApiTest() : fake_debug_daemon_client_(NULL) {} |
| 59 |
| 60 virtual ~LogPrivateApiTest() { |
| 61 } |
| 62 |
| 63 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 64 chromeos::FakeDBusThreadManager* fake_dbus_thread_manager = |
| 65 new chromeos::FakeDBusThreadManager; |
| 66 fake_dbus_thread_manager->SetFakeClients(); |
| 67 fake_debug_daemon_client_ = new TestDebugDaemonClient; |
| 68 fake_dbus_thread_manager->SetDebugDaemonClient( |
| 69 scoped_ptr<chromeos::DebugDaemonClient>(fake_debug_daemon_client_)); |
| 70 chromeos::DBusThreadManager::SetInstanceForTesting( |
| 71 fake_dbus_thread_manager); |
| 72 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 73 } |
| 74 |
| 75 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
| 76 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); |
| 77 response->set_code(net::HTTP_OK); |
| 78 response->set_content("<html><head><title>LogPrivateTest</title>" |
| 79 "</head><body>Hello World</body></html>"); |
| 80 return response.PassAs<HttpResponse>(); |
| 81 } |
| 82 |
| 83 private: |
| 84 TestDebugDaemonClient* fake_debug_daemon_client_; |
| 85 }; |
| 86 |
| 87 IN_PROC_BROWSER_TEST_F(LogPrivateApiTest, DumpSystemLogs) { |
| 88 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs")); |
| 89 } |
| 90 |
| 91 } // namespace extensions |
| 92 |
OLD | NEW |