| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include <errno.h> | 5 #include <errno.h> |
| 6 #include <sys/file.h> | 6 #include <sys/file.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "chrome/browser/chromeos/external_metrics.h" | 10 #include "chrome/browser/chromeos/external_metrics.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 for (i = 0; i < MAXLENGTH + 99; i++) { | 96 for (i = 0; i < MAXLENGTH + 99; i++) { |
| 97 b[i] = 'x'; | 97 b[i] = 'x'; |
| 98 } | 98 } |
| 99 b[i] = '\0'; | 99 b[i] = '\0'; |
| 100 SendMessage(path, b, "yyy"); | 100 SendMessage(path, b, "yyy"); |
| 101 external_metrics->CollectEvents(); | 101 external_metrics->CollectEvents(); |
| 102 EXPECT_EQ(received_count, npairs); | 102 EXPECT_EQ(received_count, npairs); |
| 103 | 103 |
| 104 // Sends a malformed message (first string is not null-terminated). | 104 // Sends a malformed message (first string is not null-terminated). |
| 105 i = 100 + sizeof(i); | 105 i = 100 + sizeof(i); |
| 106 int fd = open(path, O_CREAT | O_WRONLY); | 106 int fd = open(path, O_CREAT | O_WRONLY, 0666); |
| 107 EXPECT_GT(fd, 0); | 107 EXPECT_GT(fd, 0); |
| 108 EXPECT_EQ(write(fd, &i, sizeof(i)), static_cast<int>(sizeof(i))); | 108 EXPECT_EQ(write(fd, &i, sizeof(i)), static_cast<int>(sizeof(i))); |
| 109 EXPECT_EQ(write(fd, b, i), i); | 109 EXPECT_EQ(write(fd, b, i), i); |
| 110 EXPECT_EQ(close(fd), 0); | 110 EXPECT_EQ(close(fd), 0); |
| 111 | 111 |
| 112 external_metrics->CollectEvents(); | 112 external_metrics->CollectEvents(); |
| 113 EXPECT_EQ(received_count, npairs); | 113 EXPECT_EQ(received_count, npairs); |
| 114 | 114 |
| 115 // Sends a malformed message (second string is not null-terminated). | 115 // Sends a malformed message (second string is not null-terminated). |
| 116 b[50] = '\0'; | 116 b[50] = '\0'; |
| 117 fd = open(path, O_CREAT | O_WRONLY); | 117 fd = open(path, O_CREAT | O_WRONLY, 0666); |
| 118 EXPECT_GT(fd, 0); | 118 EXPECT_GT(fd, 0); |
| 119 EXPECT_EQ(write(fd, &i, sizeof(i)), static_cast<int>(sizeof(i))); | 119 EXPECT_EQ(write(fd, &i, sizeof(i)), static_cast<int>(sizeof(i))); |
| 120 EXPECT_EQ(write(fd, b, i), i); | 120 EXPECT_EQ(write(fd, b, i), i); |
| 121 EXPECT_EQ(close(fd), 0); | 121 EXPECT_EQ(close(fd), 0); |
| 122 | 122 |
| 123 external_metrics->CollectEvents(); | 123 external_metrics->CollectEvents(); |
| 124 EXPECT_EQ(received_count, npairs); | 124 EXPECT_EQ(received_count, npairs); |
| 125 | 125 |
| 126 // Checks that we survive when file doesn't exist. | 126 // Checks that we survive when file doesn't exist. |
| 127 EXPECT_EQ(unlink(path), 0); | 127 EXPECT_EQ(unlink(path), 0); |
| 128 external_metrics->CollectEvents(); | 128 external_metrics->CollectEvents(); |
| 129 EXPECT_EQ(received_count, npairs); | 129 EXPECT_EQ(received_count, npairs); |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace chromeos | 132 } // namespace chromeos |
| OLD | NEW |