From 3136f833a5a9921cc0e7e55d2c5776506b8ea0fe Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 31 Oct 2017 13:51:44 -0400 Subject: [PATCH] fixes and updates to GetParameters --- atom/common/api/atom_api_crash_reporter.cc | 2 +- atom/common/crash_reporter/crash_reporter.cc | 5 ++- atom/common/crash_reporter/crash_reporter.h | 2 +- .../crash_reporter/crash_reporter_mac.mm | 5 +-- lib/common/api/crash-reporter.js | 2 +- spec/api-crash-reporter-spec.js | 32 +++++++++++++++---- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/atom/common/api/atom_api_crash_reporter.cc b/atom/common/api/atom_api_crash_reporter.cc index 255283ab76..b3d395aa26 100644 --- a/atom/common/api/atom_api_crash_reporter.cc +++ b/atom/common/api/atom_api_crash_reporter.cc @@ -39,7 +39,7 @@ void RemoveExtraParameter(const std::string& key) { CrashReporter::GetInstance()->RemoveExtraParameter(key); } -crash_reporter::CrashReporter::StringMap GetParameters() { +std::map GetParameters() { return CrashReporter::GetInstance()->GetParameters(); } diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index b65720b8bc..0793c05666 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/atom/common/crash_reporter/crash_reporter.cc @@ -80,8 +80,7 @@ void CrashReporter::InitBreakpad(const std::string& product_name, const std::string& submit_url, const base::FilePath& crashes_dir, bool auto_submit, - bool skip_system_crash_handler) { -} + bool skip_system_crash_handler) {} void CrashReporter::SetUploadParameters() {} @@ -90,7 +89,7 @@ void CrashReporter::SetExtraParameter(const std::string& key, void CrashReporter::RemoveExtraParameter(const std::string& key) {} -StringMap CrashReporter::GetParameters() { +std::map CrashReporter::GetParameters() { return upload_parameters_; } diff --git a/atom/common/crash_reporter/crash_reporter.h b/atom/common/crash_reporter/crash_reporter.h index 1ef16ed505..ca85ad7177 100644 --- a/atom/common/crash_reporter/crash_reporter.h +++ b/atom/common/crash_reporter/crash_reporter.h @@ -40,7 +40,7 @@ class CrashReporter { virtual void SetExtraParameter(const std::string& key, const std::string& value); virtual void RemoveExtraParameter(const std::string& key); - virtual CrashReporter::StringMap GetParameters(); + virtual std::map GetParameters(); protected: CrashReporter(); diff --git a/atom/common/crash_reporter/crash_reporter_mac.mm b/atom/common/crash_reporter/crash_reporter_mac.mm index 990e1b3b19..bd8660f05d 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.mm +++ b/atom/common/crash_reporter/crash_reporter_mac.mm @@ -107,10 +107,11 @@ void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key, void CrashReporterMac::SetExtraParameter(const std::string& key, const std::string& value) { - if (simple_string_dictionary_) + if (simple_string_dictionary_) { SetCrashKeyValue(key, value); - else + } else { upload_parameters_[key] = value; + } } void CrashReporterMac::RemoveExtraParameter(const std::string& key) { diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index 6b9f14a978..7cbf1e2b79 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -110,7 +110,7 @@ class CrashReporter { } getParameters (key, value) { - binding.getParameters() + return binding.getParameters() } } diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index 411186205e..e7c56a1ca8 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -321,31 +321,49 @@ describe('crashReporter module', () => { }) }) - describe('Parameters', () => { + describe.only('Parameters', () => { it('returns all of the current parameters', () => { + crashReporter.start({ + companyName: 'Umbrella Corporation', + submitURL: 'http://127.0.0.1/crashes' + }) + const parameters = crashReporter.getParameters() - assert(typeof parameters === Object) + assert(typeof parameters === 'object') }) it('adds a parameter', () => { // only run on MacOS if (process.platform !== 'darwin') return - crashReporter.addParameter('hello', 'world') + crashReporter.start({ + companyName: 'Umbrella Corporation', + submitURL: 'http://127.0.0.1/crashes' + }) + + crashReporter.setExtraParameter('hello', 'world') const updatedParams = crashReporter.getParameters() - assert(updatedParams.includes('hello')) + console.log(updatedParams) + + assert('hello' in updatedParams) }) it('removes a parameter', () => { // only run on MacOS if (process.platform !== 'darwin') return - crashReporter.addParameter('hello', 'world') + crashReporter.start({ + companyName: 'Umbrella Corporation', + submitURL: 'http://127.0.0.1/crashes' + }) + + crashReporter.setExtraParameter('hello', 'world') const originalParams = crashReporter.getParameters() - assert(originalParams.includes('hello')) + console.log(originalParams) + assert('hello' in originalParams) crashReporter.removeExtraParameter('hello') const updatedParams = crashReporter.getParameters() - assert(!updatedParams.includes('hello')) + assert(!('hello' in originalParams)) }) }) })