Merge pull request #3128 from atom/fix-save-page-position

Fix: 'savePage API' saves external resources in a wrong directory.
This commit is contained in:
Cheng Zhao 2015-10-19 16:40:45 +08:00
commit 0d9e0a38c0
5 changed files with 28 additions and 6 deletions

View file

@ -36,8 +36,13 @@ bool SavePageHandler::Handle(const base::FilePath& full_path,
auto download_manager = content::BrowserContext::GetDownloadManager(
web_contents_->GetBrowserContext());
download_manager->AddObserver(this);
// Chromium will create a 'foo_files' directory under the directory of saving
// page 'foo.html' for holding other resource files of 'foo.html'.
base::FilePath saved_main_directory_path = full_path.DirName().Append(
full_path.RemoveExtension().BaseName().value() +
FILE_PATH_LITERAL("_files"));
bool result = web_contents_->SavePage(full_path,
full_path.DirName(),
saved_main_directory_path,
save_type);
download_manager->RemoveObserver(this);
// If initialization fails which means fail to create |DownloadItem|, we need

View file

@ -303,13 +303,22 @@ describe 'browser-window module', ->
done()
describe 'save page', ->
savePagePath = path.join fixtures, 'save_page.html'
savePageDir = path.join fixtures, 'save_page'
savePageHtmlPath = path.join savePageDir, 'save_page.html'
savePageJsPath = path.join savePageDir, 'save_page_files', 'test.js'
savePageCssPath = path.join savePageDir, 'save_page_files', 'test.css'
it 'should save page', (done) ->
w.webContents.on 'did-finish-load', ->
w.webContents.savePage savePagePath, 'HTMLComplete', (error) ->
w.webContents.savePage savePageHtmlPath, 'HTMLComplete', (error) ->
assert.equal error, null
assert fs.existsSync savePagePath
fs.unlinkSync savePagePath
assert fs.existsSync savePageHtmlPath
assert fs.existsSync savePageJsPath
assert fs.existsSync savePageCssPath
fs.unlinkSync savePageCssPath
fs.unlinkSync savePageJsPath
fs.unlinkSync savePageHtmlPath
fs.rmdirSync path.join savePageDir, 'save_page_files'
fs.rmdirSync savePageDir
done()
w.loadUrl "file://#{fixtures}/api/blank.html"
w.loadUrl "file://#{fixtures}/pages/save_page/index.html"

View file

@ -0,0 +1,6 @@
<html>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="test.css"></script>
<body>
</body>
</html>

View file

@ -0,0 +1 @@
h1 { }

1
spec/fixtures/pages/save_page/test.js vendored Normal file
View file

@ -0,0 +1 @@
console.log('save_page');