Skip to content

Commit

Permalink
Create a skeleton updater main for Windows.
Browse files Browse the repository at this point in the history
This change builds an executable program on Windows, which returns
a hardcoded value. The value is tested by a unit test.

The updater executable contains a valid resource file and manifest.

An upcoming change will hook the test with the test bots.
Then, another change will implement a similar function for macOS.

Bug: 925489
Change-Id: Id97f4740a2cd9e3d21c00e631a8e03c19757468a
Reviewed-on: https://chromium-review.googlesource.com/c/1437266
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Joshua Pawlicki <waffles@chromium.org>
Commit-Queue: Sorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#627053}
  • Loading branch information
sorinj authored and Commit Bot committed Jan 29, 2019
1 parent 5323996 commit 58a93ad
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ group("gn_all") {
"//base:base_perftests",
"//base:base_unittests",
"//chrome/installer",
"//chrome/updater",
"//net:net_unittests",
"//skia:skia_unittests",
"//sql:sql_unittests",
Expand Down
5 changes: 5 additions & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4554,6 +4554,11 @@ test("unit_tests") {
if (enable_widevine && is_win) {
sources += [ "../gpu/widevine_cdm_proxy_factory_unittest.cc" ]
}

# Chrome desktop updater tests.
if (is_win || is_mac) {
deps += [ "//chrome/updater:updater_tests" ]
}
}

static_library("test_support_unit") {
Expand Down
34 changes: 34 additions & 0 deletions chrome/updater/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2019 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.

import("//build/config/chrome_build.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//testing/test.gni")

group("updater") {
if (is_win) {
deps = [
"//chrome/updater/win",
]
}
}

source_set("updater_tests") {
testonly = true
if (is_win) {
sources = [
"win/updater_unittest.cc",
]

data_deps = [
"//chrome/updater/win:updater",
]
}

deps = [
":updater",
"//base/test:test_support",
"//testing/gtest",
]
}
32 changes: 32 additions & 0 deletions chrome/updater/win/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2019 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.

import("//chrome/process_version_rc_template.gni")

group("win") {
deps = [
":updater",
]
}

executable("updater") {
sources = [
"main.cc",
"updater.rc",
]

configs += [ "//build/config/win:windowed" ]

deps = [
":version_resources",
"//build/win:default_exe_manifest",
]
}

process_version_rc_template("version_resources") {
sources = [
"updater.ver",
]
output = "$target_gen_dir/updater_exe.rc"
}
9 changes: 9 additions & 0 deletions chrome/updater/win/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2019 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 <windows.h>

int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
return 0;
}
38 changes: 38 additions & 0 deletions chrome/updater/win/updater.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Microsoft Visual C++ generated resource script.
//

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
#include "verrsrc.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"#include ""verrsrc.h""\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED

#endif // English (United States) resources

/////////////////////////////////////////////////////////////////////////////
3 changes: 3 additions & 0 deletions chrome/updater/win/updater.ver
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INTERNAL_NAME=updater_exe
ORIGINAL_FILENAME=updater.exe
PRODUCT_FULLNAME=updater
29 changes: 29 additions & 0 deletions chrome/updater/win/updater_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019 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 <windows.h>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"

// Tests the updater process returns 0 when run with no arguments.
TEST(UpdaterTest, UpdaterExitCode) {
base::FilePath::CharType buffer[MAX_PATH] = {0};
ASSERT_NE(0u, GetModuleFileName(0, buffer, base::size(buffer)));
const base::FilePath updater =
base::FilePath(buffer).DirName().Append(FILE_PATH_LITERAL("updater.exe"));
base::LaunchOptions options;
options.start_hidden = true;
auto process = base::LaunchProcess(base::CommandLine(updater), options);
ASSERT_TRUE(process.IsValid());
int exit_code = -1;
EXPECT_TRUE(process.WaitForExitWithTimeout(base::TimeDelta::FromSeconds(60),
&exit_code));
EXPECT_EQ(0, exit_code);
}

0 comments on commit 58a93ad

Please sign in to comment.