Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc

Issue 2835233002: Fix integration tests in src/chrome and src/extensions so that we can turn on IO thread checks wi... (Closed)
Patch Set: ready for review Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Disable everything on windows only. http://crbug.com/306144 5 // Disable everything on windows only. http://crbug.com/306144
6 #ifndef OS_WIN 6 #ifndef OS_WIN
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/guid.h" 15 #include "base/guid.h"
16 #include "base/json/json_reader.h" 16 #include "base/json/json_reader.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/threading/thread_restrictions.h"
22 #include "build/build_config.h" 23 #include "build/build_config.h"
23 #include "chrome/browser/download/download_file_icon_extractor.h" 24 #include "chrome/browser/download/download_file_icon_extractor.h"
24 #include "chrome/browser/download/download_service.h" 25 #include "chrome/browser/download/download_service.h"
25 #include "chrome/browser/download/download_service_factory.h" 26 #include "chrome/browser/download/download_service_factory.h"
26 #include "chrome/browser/download/download_test_file_activity_observer.h" 27 #include "chrome/browser/download/download_test_file_activity_observer.h"
27 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 28 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
28 #include "chrome/browser/extensions/browser_action_test_util.h" 29 #include "chrome/browser/extensions/browser_action_test_util.h"
29 #include "chrome/browser/extensions/extension_apitest.h" 30 #include "chrome/browser/extensions/extension_apitest.h"
30 #include "chrome/browser/extensions/extension_function_test_utils.h" 31 #include "chrome/browser/extensions/extension_function_test_utils.h"
31 #include "chrome/browser/net/url_request_mock_util.h" 32 #include "chrome/browser/net/url_request_mock_util.h"
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller); 689 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller);
689 }; 690 };
690 691
691 // Writes an HTML5 file so that it can be downloaded. 692 // Writes an HTML5 file so that it can be downloaded.
692 class HTML5FileWriter { 693 class HTML5FileWriter {
693 public: 694 public:
694 static bool CreateFileForTesting(storage::FileSystemContext* context, 695 static bool CreateFileForTesting(storage::FileSystemContext* context,
695 const storage::FileSystemURL& path, 696 const storage::FileSystemURL& path,
696 const char* data, 697 const char* data,
697 int length) { 698 int length) {
699 base::ThreadRestrictions::ScopedAllowIO allow_io;
698 // Create a temp file. 700 // Create a temp file.
699 base::FilePath temp_file; 701 base::FilePath temp_file;
700 if (!base::CreateTemporaryFile(&temp_file) || 702 if (!base::CreateTemporaryFile(&temp_file) ||
701 base::WriteFile(temp_file, data, length) != length) { 703 base::WriteFile(temp_file, data, length) != length) {
702 return false; 704 return false;
703 } 705 }
704 // Invoke the fileapi to copy it into the sandboxed filesystem. 706 // Invoke the fileapi to copy it into the sandboxed filesystem.
705 bool result = false; 707 bool result = false;
706 base::RunLoop run_loop; 708 base::RunLoop run_loop;
707 BrowserThread::PostTask( 709 BrowserThread::PostTask(
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 DownloadItem::COMPLETE, 1045 DownloadItem::COMPLETE,
1044 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } 1046 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }
1045 }; 1047 };
1046 DownloadManager::DownloadVector all_downloads; 1048 DownloadManager::DownloadVector all_downloads;
1047 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), 1049 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo),
1048 &all_downloads)); 1050 &all_downloads));
1049 1051
1050 base::FilePath real_path = all_downloads[0]->GetTargetFilePath(); 1052 base::FilePath real_path = all_downloads[0]->GetTargetFilePath();
1051 base::FilePath fake_path = all_downloads[1]->GetTargetFilePath(); 1053 base::FilePath fake_path = all_downloads[1]->GetTargetFilePath();
1052 1054
1053 EXPECT_EQ(0, base::WriteFile(real_path, "", 0)); 1055 {
1054 ASSERT_TRUE(base::PathExists(real_path)); 1056 base::ThreadRestrictions::ScopedAllowIO allow_io;
1055 ASSERT_FALSE(base::PathExists(fake_path)); 1057 EXPECT_EQ(0, base::WriteFile(real_path, "", 0));
1058 ASSERT_TRUE(base::PathExists(real_path));
1059 ASSERT_FALSE(base::PathExists(fake_path));
1060 }
1056 1061
1057 for (DownloadManager::DownloadVector::iterator iter = all_downloads.begin(); 1062 for (DownloadManager::DownloadVector::iterator iter = all_downloads.begin();
1058 iter != all_downloads.end(); 1063 iter != all_downloads.end();
1059 ++iter) { 1064 ++iter) {
1060 std::string result_string; 1065 std::string result_string;
1061 // Use a MockIconExtractorImpl to test if the correct path is being passed 1066 // Use a MockIconExtractorImpl to test if the correct path is being passed
1062 // into the DownloadFileIconExtractor. 1067 // into the DownloadFileIconExtractor.
1063 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction( 1068 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
1064 (*iter)->GetTargetFilePath(), IconLoader::NORMAL, "hello"), 1069 (*iter)->GetTargetFilePath(), IconLoader::NORMAL, "hello"),
1065 base::StringPrintf("[%d, {\"size\": 32}]", (*iter)->GetId()), 1070 base::StringPrintf("[%d, {\"size\": 32}]", (*iter)->GetId()),
(...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 " \"current\": \"%s\"}}]", 2580 " \"current\": \"%s\"}}]",
2576 result_id, 2581 result_id,
2577 GetFilename("on_record.txt").c_str()))); 2582 GetFilename("on_record.txt").c_str())));
2578 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, 2583 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2579 base::StringPrintf( 2584 base::StringPrintf(
2580 "[{\"id\": %d," 2585 "[{\"id\": %d,"
2581 " \"state\": {" 2586 " \"state\": {"
2582 " \"previous\": \"in_progress\"," 2587 " \"previous\": \"in_progress\","
2583 " \"current\": \"complete\"}}]", 2588 " \"current\": \"complete\"}}]",
2584 result_id))); 2589 result_id)));
2590 base::ThreadRestrictions::ScopedAllowIO allow_io;
2585 std::string disk_data; 2591 std::string disk_data;
2586 EXPECT_TRUE(base::ReadFileToString(item->GetTargetFilePath(), &disk_data)); 2592 EXPECT_TRUE(base::ReadFileToString(item->GetTargetFilePath(), &disk_data));
2587 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2593 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2588 } 2594 }
2589 2595
2590 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2596 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2591 DownloadExtensionTest_OnDeterminingFilename_NoChange) { 2597 DownloadExtensionTest_OnDeterminingFilename_NoChange) {
2592 GoOnTheRecord(); 2598 GoOnTheRecord();
2593 LoadExtension("downloads_split"); 2599 LoadExtension("downloads_split");
2594 AddFilenameDeterminer(); 2600 AddFilenameDeterminer();
(...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after
4297 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); 4303 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action);
4298 EXPECT_FALSE(warnings.empty()); 4304 EXPECT_FALSE(warnings.empty());
4299 EXPECT_EQ(Warning::kDownloadFilenameConflict, 4305 EXPECT_EQ(Warning::kDownloadFilenameConflict,
4300 warnings.begin()->warning_type()); 4306 warnings.begin()->warning_type());
4301 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); 4307 EXPECT_EQ("incumbent", warnings.begin()->extension_id());
4302 } 4308 }
4303 4309
4304 } // namespace extensions 4310 } // namespace extensions
4305 4311
4306 #endif // http://crbug.com/306144 4312 #endif // http://crbug.com/306144
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698