summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.gyp1
-rw-r--r--base/sys_string_conversions.h3
-rw-r--r--base/sys_string_conversions_mac.mm6
-rw-r--r--base/sys_string_conversions_mac_unittest.mm19
-rw-r--r--chrome/browser/cocoa/bug_report_window_controller.mm11
-rw-r--r--chrome/browser/cocoa/bug_report_window_controller_unittest.mm7
6 files changed, 35 insertions, 12 deletions
diff --git a/base/base.gyp b/base/base.gyp
index f09e2e5..31d9d49 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -621,6 +621,7 @@
'string_tokenizer_unittest.cc',
'string_util_unittest.cc',
'sys_info_unittest.cc',
+ 'sys_string_conversions_mac_unittest.mm',
'sys_string_conversions_unittest.cc',
'system_monitor_unittest.cc',
'task_unittest.cc',
diff --git a/base/sys_string_conversions.h b/base/sys_string_conversions.h
index 18be826..edf4dd2 100644
--- a/base/sys_string_conversions.h
+++ b/base/sys_string_conversions.h
@@ -71,7 +71,8 @@ std::string SysCFStringRefToUTF8(CFStringRef ref);
string16 SysCFStringRefToUTF16(CFStringRef ref);
std::wstring SysCFStringRefToWide(CFStringRef ref);
-// Same, but accepts NSString input.
+// Same, but accepts NSString input. Converts nil NSString* to the appropriate
+// string type of length 0.
std::string SysNSStringToUTF8(NSString* ref);
string16 SysNSStringToUTF16(NSString* ref);
std::wstring SysNSStringToWide(NSString* ref);
diff --git a/base/sys_string_conversions_mac.mm b/base/sys_string_conversions_mac.mm
index d0b2b235c..9b9a07e 100644
--- a/base/sys_string_conversions_mac.mm
+++ b/base/sys_string_conversions_mac.mm
@@ -184,14 +184,20 @@ std::wstring SysCFStringRefToWide(CFStringRef ref) {
}
std::string SysNSStringToUTF8(NSString* nsstring) {
+ if (!nsstring)
+ return std::string();
return SysCFStringRefToUTF8(reinterpret_cast<CFStringRef>(nsstring));
}
string16 SysNSStringToUTF16(NSString* nsstring) {
+ if (!nsstring)
+ return string16();
return SysCFStringRefToUTF16(reinterpret_cast<CFStringRef>(nsstring));
}
std::wstring SysNSStringToWide(NSString* nsstring) {
+ if (!nsstring)
+ return std::wstring();
return SysCFStringRefToWide(reinterpret_cast<CFStringRef>(nsstring));
}
diff --git a/base/sys_string_conversions_mac_unittest.mm b/base/sys_string_conversions_mac_unittest.mm
new file mode 100644
index 0000000..628b515
--- /dev/null
+++ b/base/sys_string_conversions_mac_unittest.mm
@@ -0,0 +1,19 @@
+// Copyright (c) 2009 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 <Foundation/Foundation.h>
+
+#include "base/string16.h"
+#include "base/sys_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(SysStrings, ConversionsFromNSString) {
+ EXPECT_STREQ("Hello, world!",
+ base::SysNSStringToUTF8(@"Hello, world!").c_str());
+
+ // Conversions should be able to handle a NULL value without crashing.
+ EXPECT_STREQ("", base::SysNSStringToUTF8(nil).c_str());
+ EXPECT_EQ(string16(), base::SysNSStringToUTF16(nil));
+ EXPECT_STREQ(L"", base::SysNSStringToWide(nil).c_str());
+}
diff --git a/chrome/browser/cocoa/bug_report_window_controller.mm b/chrome/browser/cocoa/bug_report_window_controller.mm
index d61adc4..a22e822 100644
--- a/chrome/browser/cocoa/bug_report_window_controller.mm
+++ b/chrome/browser/cocoa/bug_report_window_controller.mm
@@ -33,7 +33,6 @@
if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
currentTab_ = currentTab;
profile_ = profile;
- [self setBugDescription:@""];
if (currentTab_ != NULL) {
// Get data from current tab, if one exists. This dialog could be called
@@ -69,10 +68,6 @@
l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_BROWSER_CRASH),
l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_OTHER_PROBLEM),
nil];
- // Because "Report Bug" is being called with no browser open in this
- // case, make URL and title empty.
- [self setPageURL:@""];
- [self setPageTitle:@""];
}
}
return self;
@@ -109,10 +104,10 @@
} else {
BugReportUtil::SendReport(
profile_,
- pageTitle_ ? base::SysNSStringToUTF8(pageTitle_) : "",
+ base::SysNSStringToUTF8(pageTitle_),
bugType_,
- pageURL_ ? base::SysNSStringToUTF8(pageURL_) : "",
- bugDescription_ ? base::SysNSStringToUTF8(bugDescription_) : "",
+ base::SysNSStringToUTF8(pageURL_),
+ base::SysNSStringToUTF8(bugDescription_),
sendScreenshot_ && !pngData_.empty() ?
reinterpret_cast<const char *>(&(pngData_[0])) : NULL,
pngData_.size());
diff --git a/chrome/browser/cocoa/bug_report_window_controller_unittest.mm b/chrome/browser/cocoa/bug_report_window_controller_unittest.mm
index 6b15c4a..4be73fb 100644
--- a/chrome/browser/cocoa/bug_report_window_controller_unittest.mm
+++ b/chrome/browser/cocoa/bug_report_window_controller_unittest.mm
@@ -54,9 +54,10 @@ TEST_F(BugReportWindowControllerUnittest, ReportBugWithNoWindowOpen) {
initWithTabContents:NULL
profile:profile_.get()];
- // Make sure that no page title or URL are recorded.
- EXPECT_TRUE([[controller pageURL] isEqualToString:@""]);
- EXPECT_TRUE([[controller pageTitle] isEqualToString:@""]);
+ // Make sure that no page title or URL are recorded. Note that IB reports
+ // empty textfields as NULL values.
+ EXPECT_FALSE([controller pageURL]);
+ EXPECT_FALSE([controller pageTitle]);
// When we call "report bug" with empty tab contents, only menu options
// that don't refer to a specific page should be available, and the send